1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
package org.apache.maven.plugins.changes.model.io.xpp3; |
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
import java.io.Writer; |
12 | |
import java.text.DateFormat; |
13 | |
import java.util.Iterator; |
14 | |
import java.util.Locale; |
15 | |
import org.apache.maven.plugins.changes.model.Action; |
16 | |
import org.apache.maven.plugins.changes.model.Author; |
17 | |
import org.apache.maven.plugins.changes.model.Body; |
18 | |
import org.apache.maven.plugins.changes.model.ChangesDocument; |
19 | |
import org.apache.maven.plugins.changes.model.DueTo; |
20 | |
import org.apache.maven.plugins.changes.model.FixedIssue; |
21 | |
import org.apache.maven.plugins.changes.model.Properties; |
22 | |
import org.apache.maven.plugins.changes.model.Release; |
23 | |
import org.codehaus.plexus.util.xml.pull.MXSerializer; |
24 | |
import org.codehaus.plexus.util.xml.pull.XmlSerializer; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | 0 | public class ChangesXpp3Writer { |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
private String NAMESPACE; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
public void write(Writer writer, ChangesDocument changesDocument) |
56 | |
throws java.io.IOException |
57 | |
{ |
58 | 0 | XmlSerializer serializer = new MXSerializer(); |
59 | 0 | serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " ); |
60 | 0 | serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" ); |
61 | 0 | serializer.setOutput( writer ); |
62 | 0 | serializer.startDocument( changesDocument.getModelEncoding(), null ); |
63 | 0 | writeChangesDocument( changesDocument, "document", serializer ); |
64 | 0 | serializer.endDocument(); |
65 | 0 | } |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
private void writeAction(Action action, String tagName, XmlSerializer serializer) |
76 | |
throws java.io.IOException |
77 | |
{ |
78 | 0 | if ( action != null ) |
79 | |
{ |
80 | 0 | serializer.startTag( NAMESPACE, tagName ); |
81 | 0 | if ( action.getDev() != null ) |
82 | |
{ |
83 | 0 | serializer.attribute( NAMESPACE, "dev", action.getDev() ); |
84 | |
} |
85 | 0 | if ( action.getDueTo() != null ) |
86 | |
{ |
87 | 0 | serializer.attribute( NAMESPACE, "due-to", action.getDueTo() ); |
88 | |
} |
89 | 0 | if ( action.getDueToEmail() != null ) |
90 | |
{ |
91 | 0 | serializer.attribute( NAMESPACE, "due-to-email", action.getDueToEmail() ); |
92 | |
} |
93 | 0 | if ( action.getIssue() != null ) |
94 | |
{ |
95 | 0 | serializer.attribute( NAMESPACE, "issue", action.getIssue() ); |
96 | |
} |
97 | 0 | if ( action.getType() != null ) |
98 | |
{ |
99 | 0 | serializer.attribute( NAMESPACE, "type", action.getType() ); |
100 | |
} |
101 | 0 | if ( action.getSystem() != null ) |
102 | |
{ |
103 | 0 | serializer.attribute( NAMESPACE, "system", action.getSystem() ); |
104 | |
} |
105 | 0 | if ( action.getDate() != null ) |
106 | |
{ |
107 | 0 | serializer.attribute( NAMESPACE, "date", action.getDate() ); |
108 | |
} |
109 | 0 | serializer.text( String.valueOf( action.getAction() )); |
110 | 0 | if ( action.getFixedIssues() != null && action.getFixedIssues().size() > 0 ) |
111 | |
{ |
112 | 0 | for ( Iterator iter = action.getFixedIssues().iterator(); iter.hasNext(); ) |
113 | |
{ |
114 | 0 | FixedIssue o = (FixedIssue) iter.next(); |
115 | 0 | writeFixedIssue( o, "fixes", serializer ); |
116 | |
} |
117 | |
} |
118 | 0 | if ( action.getDueTos() != null && action.getDueTos().size() > 0 ) |
119 | |
{ |
120 | 0 | for ( Iterator iter = action.getDueTos().iterator(); iter.hasNext(); ) |
121 | |
{ |
122 | 0 | DueTo o = (DueTo) iter.next(); |
123 | 0 | writeDueTo( o, "dueto", serializer ); |
124 | |
} |
125 | |
} |
126 | 0 | serializer.endTag( NAMESPACE, tagName ); |
127 | |
} |
128 | 0 | } |
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
private void writeAuthor(Author author, String tagName, XmlSerializer serializer) |
139 | |
throws java.io.IOException |
140 | |
{ |
141 | 0 | if ( author != null ) |
142 | |
{ |
143 | 0 | serializer.startTag( NAMESPACE, tagName ); |
144 | 0 | if ( author.getAuthorEmail() != null ) |
145 | |
{ |
146 | 0 | serializer.attribute( NAMESPACE, "email", author.getAuthorEmail() ); |
147 | |
} |
148 | 0 | serializer.text( String.valueOf( author.getName() )); |
149 | 0 | serializer.endTag( NAMESPACE, tagName ); |
150 | |
} |
151 | 0 | } |
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
private void writeBody(Body body, String tagName, XmlSerializer serializer) |
162 | |
throws java.io.IOException |
163 | |
{ |
164 | 0 | if ( body != null ) |
165 | |
{ |
166 | 0 | serializer.startTag( NAMESPACE, tagName ); |
167 | 0 | if ( body.getReleases() != null && body.getReleases().size() > 0 ) |
168 | |
{ |
169 | 0 | for ( Iterator iter = body.getReleases().iterator(); iter.hasNext(); ) |
170 | |
{ |
171 | 0 | Release o = (Release) iter.next(); |
172 | 0 | writeRelease( o, "release", serializer ); |
173 | |
} |
174 | |
} |
175 | 0 | serializer.endTag( NAMESPACE, tagName ); |
176 | |
} |
177 | 0 | } |
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
private void writeChangesDocument(ChangesDocument changesDocument, String tagName, XmlSerializer serializer) |
188 | |
throws java.io.IOException |
189 | |
{ |
190 | 0 | if ( changesDocument != null ) |
191 | |
{ |
192 | 0 | serializer.startTag( NAMESPACE, tagName ); |
193 | 0 | if ( changesDocument.getProperties() != null ) |
194 | |
{ |
195 | 0 | writeProperties( (Properties) changesDocument.getProperties(), "properties", serializer ); |
196 | |
} |
197 | 0 | if ( changesDocument.getBody() != null ) |
198 | |
{ |
199 | 0 | writeBody( (Body) changesDocument.getBody(), "body", serializer ); |
200 | |
} |
201 | 0 | serializer.endTag( NAMESPACE, tagName ); |
202 | |
} |
203 | 0 | } |
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
private void writeDueTo(DueTo dueTo, String tagName, XmlSerializer serializer) |
214 | |
throws java.io.IOException |
215 | |
{ |
216 | 0 | if ( dueTo != null ) |
217 | |
{ |
218 | 0 | serializer.startTag( NAMESPACE, tagName ); |
219 | 0 | if ( dueTo.getName() != null ) |
220 | |
{ |
221 | 0 | serializer.attribute( NAMESPACE, "name", dueTo.getName() ); |
222 | |
} |
223 | 0 | if ( dueTo.getEmail() != null ) |
224 | |
{ |
225 | 0 | serializer.attribute( NAMESPACE, "email", dueTo.getEmail() ); |
226 | |
} |
227 | 0 | serializer.endTag( NAMESPACE, tagName ); |
228 | |
} |
229 | 0 | } |
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | |
private void writeFixedIssue(FixedIssue fixedIssue, String tagName, XmlSerializer serializer) |
240 | |
throws java.io.IOException |
241 | |
{ |
242 | 0 | if ( fixedIssue != null ) |
243 | |
{ |
244 | 0 | serializer.startTag( NAMESPACE, tagName ); |
245 | 0 | if ( fixedIssue.getIssue() != null ) |
246 | |
{ |
247 | 0 | serializer.attribute( NAMESPACE, "issue", fixedIssue.getIssue() ); |
248 | |
} |
249 | 0 | serializer.endTag( NAMESPACE, tagName ); |
250 | |
} |
251 | 0 | } |
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | |
|
261 | |
private void writeProperties(Properties properties, String tagName, XmlSerializer serializer) |
262 | |
throws java.io.IOException |
263 | |
{ |
264 | 0 | if ( properties != null ) |
265 | |
{ |
266 | 0 | serializer.startTag( NAMESPACE, tagName ); |
267 | 0 | if ( properties.getTitle() != null ) |
268 | |
{ |
269 | 0 | serializer.startTag( NAMESPACE, "title" ).text( properties.getTitle() ).endTag( NAMESPACE, "title" ); |
270 | |
} |
271 | 0 | if ( properties.getAuthor() != null ) |
272 | |
{ |
273 | 0 | writeAuthor( (Author) properties.getAuthor(), "author", serializer ); |
274 | |
} |
275 | 0 | serializer.endTag( NAMESPACE, tagName ); |
276 | |
} |
277 | 0 | } |
278 | |
|
279 | |
|
280 | |
|
281 | |
|
282 | |
|
283 | |
|
284 | |
|
285 | |
|
286 | |
|
287 | |
private void writeRelease(Release release, String tagName, XmlSerializer serializer) |
288 | |
throws java.io.IOException |
289 | |
{ |
290 | 0 | if ( release != null ) |
291 | |
{ |
292 | 0 | serializer.startTag( NAMESPACE, tagName ); |
293 | 0 | if ( release.getVersion() != null ) |
294 | |
{ |
295 | 0 | serializer.attribute( NAMESPACE, "version", release.getVersion() ); |
296 | |
} |
297 | 0 | if ( release.getDateRelease() != null ) |
298 | |
{ |
299 | 0 | serializer.attribute( NAMESPACE, "date", release.getDateRelease() ); |
300 | |
} |
301 | 0 | if ( release.getDescription() != null ) |
302 | |
{ |
303 | 0 | serializer.attribute( NAMESPACE, "description", release.getDescription() ); |
304 | |
} |
305 | 0 | if ( release.getActions() != null && release.getActions().size() > 0 ) |
306 | |
{ |
307 | 0 | for ( Iterator iter = release.getActions().iterator(); iter.hasNext(); ) |
308 | |
{ |
309 | 0 | Action o = (Action) iter.next(); |
310 | 0 | writeAction( o, "action", serializer ); |
311 | |
} |
312 | |
} |
313 | 0 | serializer.endTag( NAMESPACE, tagName ); |
314 | |
} |
315 | 0 | } |
316 | |
|
317 | |
|
318 | |
} |