1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.reports;
17
18 import java.io.IOException;
19 import java.io.OutputStream;
20
21 import org.apache.commons.io.IOUtils;
22
23 import de.smartics.properties.report.app.ReportException;
24 import de.smartics.properties.report.data.PropertyReportItem;
25 import de.smartics.properties.report.data.PropertyReportSet;
26 import de.smartics.util.io.StreamHandler;
27
28
29
30
31 public final class XmlPropertyReport extends AbstractPropertyReport
32 {
33
34
35
36
37
38
39
40
41
42 private final StreamHandler propertySetReportsRootDir;
43
44
45
46
47 private final StreamHandler propertyReportsRootDir;
48
49
50
51
52
53
54
55
56
57
58
59
60
61 public XmlPropertyReport(final StreamHandler propertySetReportsRootDir,
62 final StreamHandler propertyReportsRootDir)
63 {
64 this.propertySetReportsRootDir = propertySetReportsRootDir;
65 this.propertyReportsRootDir = propertyReportsRootDir;
66 }
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 @Override
84 public void handle(final PropertyReportSet reportSet) throws ReportException
85 {
86 final String resourceId = reportSet.getName() + ".xml";
87 OutputStream out = null;
88 try
89 {
90 out = propertySetReportsRootDir.openToWrite(resourceId);
91 final PropertySetReporter reporter = new PropertySetReporter(reportSet);
92 reporter.write(out);
93 }
94 catch (final IOException e)
95 {
96 throw new ReportException("Cannot write report '" + resourceId + "'.", e);
97 }
98 finally
99 {
100 IOUtils.closeQuietly(out);
101 }
102 }
103
104
105
106
107
108
109 @Override
110 public void handle(final PropertyReportItem item) throws ReportException
111 {
112 super.handle(item);
113
114 final String resourceId = item.getName() + ".xml";
115 OutputStream out = null;
116 try
117 {
118 out = propertyReportsRootDir.openToWrite(resourceId);
119 final PropertyReporter reporter = new PropertyReporter(item);
120 reporter.write(out);
121 }
122 catch (final IOException e)
123 {
124 throw new ReportException("Cannot write report '" + resourceId + "'.", e);
125 }
126 finally
127 {
128 IOUtils.closeQuietly(out);
129 }
130 }
131
132
133
134 }