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 import de.smartics.util.lang.Arg;
28
29
30
31
32 public final class XmlPropertyReport extends AbstractPropertyReport
33 {
34
35
36
37
38
39
40
41
42
43 private final String encoding;
44
45
46
47
48 private final StreamHandler propertySetReportsRootDir;
49
50
51
52
53 private final StreamHandler propertyReportsRootDir;
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 public XmlPropertyReport(final StreamHandler propertySetReportsRootDir,
70 final StreamHandler propertyReportsRootDir) throws NullPointerException
71 {
72 this("UTF-8", propertySetReportsRootDir, propertyReportsRootDir);
73 }
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88 public XmlPropertyReport(final String encoding,
89 final StreamHandler propertySetReportsRootDir,
90 final StreamHandler propertyReportsRootDir) throws NullPointerException,
91 IllegalArgumentException
92 {
93 this.encoding = Arg.checkNotBlank("encoding", encoding);
94 this.propertySetReportsRootDir =
95 Arg.checkNotNull("propertySetReportsRootDir", propertySetReportsRootDir);
96 this.propertyReportsRootDir =
97 Arg.checkNotNull("propertyReportsRootDir", propertyReportsRootDir);
98 }
99
100
101
102
103
104
105
106
107
108
109
110 @Override
111 public void handle(final PropertyReportSet reportSet) throws ReportException
112 {
113 final String resourceId = reportSet.getName() + ".xml";
114 OutputStream out = null;
115 try
116 {
117 out = propertySetReportsRootDir.openToWrite(resourceId);
118 final XmlPropertySetReporter reporter =
119 new XmlPropertySetReporter(encoding, reportSet);
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 @Override
133 public void handle(final PropertyReportItem item) throws ReportException
134 {
135 super.handle(item);
136
137 final String resourceId = item.getName() + ".xml";
138 OutputStream out = null;
139 try
140 {
141 out = propertyReportsRootDir.openToWrite(resourceId);
142 final XmlPropertyReporter reporter =
143 new XmlPropertyReporter(encoding, item);
144 reporter.write(out);
145 }
146 catch (final IOException e)
147 {
148 throw new ReportException("Cannot write report '" + resourceId + "'.", e);
149 }
150 finally
151 {
152 IOUtils.closeQuietly(out);
153 }
154 }
155
156
157
158 }