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