1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package de.smartics.maven.issues.bugzilla;
18
19 import java.io.IOException;
20 import java.io.StringReader;
21 import java.util.List;
22 import java.util.ResourceBundle;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.maven.doxia.module.xdoc.XdocParser;
27 import org.apache.maven.doxia.parser.ParseException;
28 import org.apache.maven.doxia.sink.Sink;
29 import org.apache.maven.reporting.AbstractMavenReportRenderer;
30 import org.codehaus.plexus.util.StringUtils;
31 import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute;
32 import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
33 import org.eclipse.mylyn.tasks.core.data.TaskData;
34
35 import de.smartics.maven.issues.RendererConfig;
36
37
38
39
40
41
42 public abstract class AbstractIssuesReportRenderer extends
43 AbstractMavenReportRenderer
44 {
45
46
47
48
49
50
51
52 private static final Log LOG = LogFactory
53 .getLog(AbstractIssuesReportRenderer.class);
54
55
56
57
58
59
60 protected final RendererConfig config;
61
62
63
64
65 protected final List<TaskData> issues;
66
67
68
69
70
71
72
73
74
75
76
77
78 protected AbstractIssuesReportRenderer(final RendererConfig config,
79 final Sink sink, final List<TaskData> issues)
80 {
81 super(sink);
82 this.config = config;
83 this.issues = issues;
84 if (LOG.isTraceEnabled())
85 {
86 LOG.trace("Created renderer class instance '" + getClass().getName()
87 + "' using this configuration: " + config);
88 }
89 }
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104 protected abstract String getDescription();
105
106
107
108
109
110
111 protected abstract String getNoResultsDescription();
112
113
114
115
116
117
118
119
120 protected String getTitle(final String key)
121 {
122 final String title = config.getTitle();
123 if (title != null)
124 {
125 return title;
126 }
127 return config.getBundle().getString(key);
128 }
129
130
131
132
133
134
135
136
137 protected String getDescription(final String key)
138 {
139 final String description = config.getDescription();
140 if (description != null)
141 {
142 return description;
143 }
144 return config.getBundle().getString(key);
145 }
146
147
148
149
150
151
152
153
154
155 protected String getNoResultsDescription(final String key)
156 {
157 final String description = config.getNoResultsDescription();
158 if (description != null)
159 {
160 return description;
161 }
162 return config.getBundle().getString(key);
163 }
164
165
166
167
168
169
170
171
172
173 protected void renderTitle(final boolean noResults)
174 {
175 sink.sectionTitle1();
176 sink.text(getTitle());
177 sink.sectionTitle1_();
178 renderDescription(noResults);
179 }
180
181
182
183
184
185
186
187 private void renderDescription(final boolean noResults)
188 {
189 if (noResults)
190 {
191 final String description = getNoResultsDescription();
192 if (StringUtils.isNotBlank(description))
193 {
194 sink.paragraph();
195 sink.text(description);
196 sink.paragraph_();
197 }
198 }
199 else
200 {
201 final boolean written = writeBodyContent();
202 if (!written)
203 {
204 final String description = getDescription();
205 if (StringUtils.isNotBlank(description))
206 {
207 sink.paragraph();
208 sink.text(description);
209 sink.paragraph_();
210 }
211 }
212 }
213 }
214
215
216
217
218
219
220
221 private boolean writeBodyContent()
222 {
223 try
224 {
225 final String bodyContent = config.getDescriptionFileBodyContent();
226 if (!"".equals(bodyContent))
227 {
228 final XdocParser parser = new XdocParser();
229 parser.parse(new StringReader(bodyContent), sink);
230
231 return true;
232 }
233 }
234 catch (final IOException e)
235 {
236 if (LOG.isWarnEnabled())
237 {
238 LOG.warn("Cannot read description file '"
239 + config.getDescriptionFile().getAbsolutePath() + "'.");
240 }
241 }
242 catch (final ParseException e)
243 {
244 if (LOG.isWarnEnabled())
245 {
246 LOG.warn("Cannot read description file '"
247 + config.getDescriptionFile().getAbsolutePath() + "'.");
248 }
249 }
250 return false;
251 }
252
253
254
255
256 protected void renderFooter()
257 {
258 final String footerText = config.getFooterText();
259 if (StringUtils.isNotBlank(footerText))
260 {
261 sink.rawText(footerText);
262 }
263 }
264
265
266
267
268 protected void renderTableHeader()
269 {
270 final ResourceBundle bundle = config.getBundle();
271 final List<String> columns = config.getColumns();
272 final List<String> columnWidths = config.getColumnWidths();
273
274 int i = 0;
275 sink.tableRow();
276 for (String column : columns)
277 {
278 final String label = ReportHelper.getLabel(bundle, column);
279 final String width = columnWidths.get(i);
280 if ("0".equals(width))
281 {
282 sink.tableHeaderCell();
283 }
284 else
285 {
286 sink.tableHeaderCell(width);
287 }
288 sink.text(label);
289 sink.tableHeaderCell_();
290 i++;
291 }
292 sink.tableRow_();
293 }
294
295
296
297
298
299
300 protected void renderTableRow(final TaskData issue)
301 {
302 final boolean renderEmailAddresses = config.isRenderEmailAdresses();
303 final TaskAttribute root = issue.getRoot();
304 sink.tableRow();
305 final List<String> columns = config.getColumns();
306 for (String column : columns)
307 {
308
309
310 if (BugzillaAttribute.BUG_ID.getKey().equals(column))
311 {
312 final String id = issue.getTaskId();
313
314
315 final String url = issue.getRepositoryUrl() + "/show_bug.cgi?id=" + id;
316 ReportHelper.renderTableCellWithLink(sink, url, id);
317 }
318 else if (renderEmailAddresses
319 && ReportHelper.PERSON_NAME_TO_EMAIL.containsKey(column))
320 {
321 final String eMailKey = ReportHelper.PERSON_NAME_TO_EMAIL.get(column);
322 ReportHelper.renderTableCellWithMailto(sink, root, column, eMailKey);
323 }
324 else
325 {
326 ReportHelper.renderTableCell(sink, root, column);
327 }
328 }
329 sink.tableRow_();
330 }
331
332
333
334 }