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