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