1
2
3
4
5
6 package org.apache.maven.plugins.javadoc.options.io.xpp3;
7
8
9
10
11
12 import java.io.OutputStream;
13 import java.io.Writer;
14 import java.util.Iterator;
15 import org.apache.maven.plugins.javadoc.options.BootclasspathArtifact;
16 import org.apache.maven.plugins.javadoc.options.DocletArtifact;
17 import org.apache.maven.plugins.javadoc.options.Group;
18 import org.apache.maven.plugins.javadoc.options.JavadocOptions;
19 import org.apache.maven.plugins.javadoc.options.JavadocPathArtifact;
20 import org.apache.maven.plugins.javadoc.options.OfflineLink;
21 import org.apache.maven.plugins.javadoc.options.ResourcesArtifact;
22 import org.apache.maven.plugins.javadoc.options.Tag;
23 import org.apache.maven.plugins.javadoc.options.Taglet;
24 import org.apache.maven.plugins.javadoc.options.TagletArtifact;
25 import org.codehaus.plexus.util.xml.pull.MXSerializer;
26 import org.codehaus.plexus.util.xml.pull.XmlSerializer;
27
28
29
30
31
32
33 @SuppressWarnings( "all" )
34 public class JavadocOptionsXpp3Writer
35 {
36
37
38
39
40
41
42
43
44 private static final String NAMESPACE = null;
45
46
47
48
49 private String fileComment = null;
50
51
52
53
54
55
56
57
58
59
60
61 public void setFileComment( String fileComment )
62 {
63 this.fileComment = fileComment;
64 }
65
66
67
68
69
70
71
72
73 public void write( Writer writer, JavadocOptions javadocOptions )
74 throws java.io.IOException
75 {
76 XmlSerializer serializer = new MXSerializer();
77 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " );
78 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
79 serializer.setOutput( writer );
80 serializer.startDocument( javadocOptions.getModelEncoding(), null );
81 writeJavadocOptions( javadocOptions, "javadocOptions", serializer );
82 serializer.endDocument();
83 }
84
85
86
87
88
89
90
91
92 public void write( OutputStream stream, JavadocOptions javadocOptions )
93 throws java.io.IOException
94 {
95 XmlSerializer serializer = new MXSerializer();
96 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " );
97 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
98 serializer.setOutput( stream, javadocOptions.getModelEncoding() );
99 serializer.startDocument( javadocOptions.getModelEncoding(), null );
100 writeJavadocOptions( javadocOptions, "javadocOptions", serializer );
101 serializer.endDocument();
102 }
103
104
105
106
107
108
109
110
111
112 private void writeBootclasspathArtifact( BootclasspathArtifact bootclasspathArtifact, String tagName, XmlSerializer serializer )
113 throws java.io.IOException
114 {
115 serializer.startTag( NAMESPACE, tagName );
116 if ( bootclasspathArtifact.getGroupId() != null )
117 {
118 serializer.startTag( NAMESPACE, "groupId" ).text( bootclasspathArtifact.getGroupId() ).endTag( NAMESPACE, "groupId" );
119 }
120 if ( bootclasspathArtifact.getArtifactId() != null )
121 {
122 serializer.startTag( NAMESPACE, "artifactId" ).text( bootclasspathArtifact.getArtifactId() ).endTag( NAMESPACE, "artifactId" );
123 }
124 if ( bootclasspathArtifact.getVersion() != null )
125 {
126 serializer.startTag( NAMESPACE, "version" ).text( bootclasspathArtifact.getVersion() ).endTag( NAMESPACE, "version" );
127 }
128 if ( bootclasspathArtifact.getClassifier() != null )
129 {
130 serializer.startTag( NAMESPACE, "classifier" ).text( bootclasspathArtifact.getClassifier() ).endTag( NAMESPACE, "classifier" );
131 }
132 serializer.endTag( NAMESPACE, tagName );
133 }
134
135
136
137
138
139
140
141
142
143 private void writeDocletArtifact( DocletArtifact docletArtifact, String tagName, XmlSerializer serializer )
144 throws java.io.IOException
145 {
146 serializer.startTag( NAMESPACE, tagName );
147 if ( docletArtifact.getGroupId() != null )
148 {
149 serializer.startTag( NAMESPACE, "groupId" ).text( docletArtifact.getGroupId() ).endTag( NAMESPACE, "groupId" );
150 }
151 if ( docletArtifact.getArtifactId() != null )
152 {
153 serializer.startTag( NAMESPACE, "artifactId" ).text( docletArtifact.getArtifactId() ).endTag( NAMESPACE, "artifactId" );
154 }
155 if ( docletArtifact.getVersion() != null )
156 {
157 serializer.startTag( NAMESPACE, "version" ).text( docletArtifact.getVersion() ).endTag( NAMESPACE, "version" );
158 }
159 if ( docletArtifact.getClassifier() != null )
160 {
161 serializer.startTag( NAMESPACE, "classifier" ).text( docletArtifact.getClassifier() ).endTag( NAMESPACE, "classifier" );
162 }
163 serializer.endTag( NAMESPACE, tagName );
164 }
165
166
167
168
169
170
171
172
173
174 private void writeGroup( Group group, String tagName, XmlSerializer serializer )
175 throws java.io.IOException
176 {
177 serializer.startTag( NAMESPACE, tagName );
178 if ( group.getTitle() != null )
179 {
180 serializer.startTag( NAMESPACE, "title" ).text( group.getTitle() ).endTag( NAMESPACE, "title" );
181 }
182 if ( group.getPackages() != null )
183 {
184 serializer.startTag( NAMESPACE, "packages" ).text( group.getPackages() ).endTag( NAMESPACE, "packages" );
185 }
186 serializer.endTag( NAMESPACE, tagName );
187 }
188
189
190
191
192
193
194
195
196
197 private void writeJavadocOptions( JavadocOptions javadocOptions, String tagName, XmlSerializer serializer )
198 throws java.io.IOException
199 {
200 serializer.startTag( NAMESPACE, tagName );
201 if ( ( javadocOptions.getGroups() != null ) && ( javadocOptions.getGroups().size() > 0 ) )
202 {
203 serializer.startTag( NAMESPACE, "groups" );
204 for ( Iterator iter = javadocOptions.getGroups().iterator(); iter.hasNext(); )
205 {
206 Group o = (Group) iter.next();
207 writeGroup( o, "group", serializer );
208 }
209 serializer.endTag( NAMESPACE, "groups" );
210 }
211 if ( ( javadocOptions.getTags() != null ) && ( javadocOptions.getTags().size() > 0 ) )
212 {
213 serializer.startTag( NAMESPACE, "tags" );
214 for ( Iterator iter = javadocOptions.getTags().iterator(); iter.hasNext(); )
215 {
216 Tag o = (Tag) iter.next();
217 writeTag( o, "tag", serializer );
218 }
219 serializer.endTag( NAMESPACE, "tags" );
220 }
221 if ( ( javadocOptions.getDocletArtifacts() != null ) && ( javadocOptions.getDocletArtifacts().size() > 0 ) )
222 {
223 serializer.startTag( NAMESPACE, "docletArtifacts" );
224 for ( Iterator iter = javadocOptions.getDocletArtifacts().iterator(); iter.hasNext(); )
225 {
226 DocletArtifact o = (DocletArtifact) iter.next();
227 writeDocletArtifact( o, "docletArtifact", serializer );
228 }
229 serializer.endTag( NAMESPACE, "docletArtifacts" );
230 }
231 if ( ( javadocOptions.getTaglets() != null ) && ( javadocOptions.getTaglets().size() > 0 ) )
232 {
233 serializer.startTag( NAMESPACE, "taglets" );
234 for ( Iterator iter = javadocOptions.getTaglets().iterator(); iter.hasNext(); )
235 {
236 Taglet o = (Taglet) iter.next();
237 writeTaglet( o, "taglet", serializer );
238 }
239 serializer.endTag( NAMESPACE, "taglets" );
240 }
241 if ( ( javadocOptions.getOfflineLinks() != null ) && ( javadocOptions.getOfflineLinks().size() > 0 ) )
242 {
243 serializer.startTag( NAMESPACE, "offlineLinks" );
244 for ( Iterator iter = javadocOptions.getOfflineLinks().iterator(); iter.hasNext(); )
245 {
246 OfflineLink o = (OfflineLink) iter.next();
247 writeOfflineLink( o, "offlineLink", serializer );
248 }
249 serializer.endTag( NAMESPACE, "offlineLinks" );
250 }
251 if ( ( javadocOptions.getTagletArtifacts() != null ) && ( javadocOptions.getTagletArtifacts().size() > 0 ) )
252 {
253 serializer.startTag( NAMESPACE, "tagletArtifacts" );
254 for ( Iterator iter = javadocOptions.getTagletArtifacts().iterator(); iter.hasNext(); )
255 {
256 TagletArtifact o = (TagletArtifact) iter.next();
257 writeTagletArtifact( o, "tagletArtifact", serializer );
258 }
259 serializer.endTag( NAMESPACE, "tagletArtifacts" );
260 }
261 if ( ( javadocOptions.getResourcesArtifacts() != null ) && ( javadocOptions.getResourcesArtifacts().size() > 0 ) )
262 {
263 serializer.startTag( NAMESPACE, "resourcesArtifacts" );
264 for ( Iterator iter = javadocOptions.getResourcesArtifacts().iterator(); iter.hasNext(); )
265 {
266 ResourcesArtifact o = (ResourcesArtifact) iter.next();
267 writeResourcesArtifact( o, "resourcesArtifact", serializer );
268 }
269 serializer.endTag( NAMESPACE, "resourcesArtifacts" );
270 }
271 if ( ( javadocOptions.getBootclasspathArtifacts() != null ) && ( javadocOptions.getBootclasspathArtifacts().size() > 0 ) )
272 {
273 serializer.startTag( NAMESPACE, "bootclasspathArtifacts" );
274 for ( Iterator iter = javadocOptions.getBootclasspathArtifacts().iterator(); iter.hasNext(); )
275 {
276 BootclasspathArtifact o = (BootclasspathArtifact) iter.next();
277 writeBootclasspathArtifact( o, "bootclasspathArtifact", serializer );
278 }
279 serializer.endTag( NAMESPACE, "bootclasspathArtifacts" );
280 }
281 if ( ( javadocOptions.getLinks() != null ) && ( javadocOptions.getLinks().size() > 0 ) )
282 {
283 serializer.startTag( NAMESPACE, "links" );
284 for ( Iterator iter = javadocOptions.getLinks().iterator(); iter.hasNext(); )
285 {
286 String link = (String) iter.next();
287 serializer.startTag( NAMESPACE, "link" ).text( link ).endTag( NAMESPACE, "link" );
288 }
289 serializer.endTag( NAMESPACE, "links" );
290 }
291 if ( ( javadocOptions.getExcludePackageNames() != null ) && ( javadocOptions.getExcludePackageNames().size() > 0 ) )
292 {
293 serializer.startTag( NAMESPACE, "excludePackageNames" );
294 for ( Iterator iter = javadocOptions.getExcludePackageNames().iterator(); iter.hasNext(); )
295 {
296 String excludePackageName = (String) iter.next();
297 serializer.startTag( NAMESPACE, "excludePackageName" ).text( excludePackageName ).endTag( NAMESPACE, "excludePackageName" );
298 }
299 serializer.endTag( NAMESPACE, "excludePackageNames" );
300 }
301 if ( javadocOptions.isDocfilesSubdirsUsed() != false )
302 {
303 serializer.startTag( NAMESPACE, "docfilesSubdirsUsed" ).text( String.valueOf( javadocOptions.isDocfilesSubdirsUsed() ) ).endTag( NAMESPACE, "docfilesSubdirsUsed" );
304 }
305 if ( javadocOptions.getExcludedDocfilesSubdirs() != null )
306 {
307 serializer.startTag( NAMESPACE, "excludedDocfilesSubdirs" ).text( javadocOptions.getExcludedDocfilesSubdirs() ).endTag( NAMESPACE, "excludedDocfilesSubdirs" );
308 }
309 if ( javadocOptions.getJavadocResourcesDirectory() != null )
310 {
311 serializer.startTag( NAMESPACE, "javadocResourcesDirectory" ).text( javadocOptions.getJavadocResourcesDirectory() ).endTag( NAMESPACE, "javadocResourcesDirectory" );
312 }
313 serializer.endTag( NAMESPACE, tagName );
314 }
315
316
317
318
319
320
321
322
323
324 private void writeJavadocPathArtifact( JavadocPathArtifact javadocPathArtifact, String tagName, XmlSerializer serializer )
325 throws java.io.IOException
326 {
327 serializer.startTag( NAMESPACE, tagName );
328 if ( javadocPathArtifact.getGroupId() != null )
329 {
330 serializer.startTag( NAMESPACE, "groupId" ).text( javadocPathArtifact.getGroupId() ).endTag( NAMESPACE, "groupId" );
331 }
332 if ( javadocPathArtifact.getArtifactId() != null )
333 {
334 serializer.startTag( NAMESPACE, "artifactId" ).text( javadocPathArtifact.getArtifactId() ).endTag( NAMESPACE, "artifactId" );
335 }
336 if ( javadocPathArtifact.getVersion() != null )
337 {
338 serializer.startTag( NAMESPACE, "version" ).text( javadocPathArtifact.getVersion() ).endTag( NAMESPACE, "version" );
339 }
340 if ( javadocPathArtifact.getClassifier() != null )
341 {
342 serializer.startTag( NAMESPACE, "classifier" ).text( javadocPathArtifact.getClassifier() ).endTag( NAMESPACE, "classifier" );
343 }
344 serializer.endTag( NAMESPACE, tagName );
345 }
346
347
348
349
350
351
352
353
354
355 private void writeOfflineLink( OfflineLink offlineLink, String tagName, XmlSerializer serializer )
356 throws java.io.IOException
357 {
358 serializer.startTag( NAMESPACE, tagName );
359 if ( offlineLink.getUrl() != null )
360 {
361 serializer.startTag( NAMESPACE, "url" ).text( offlineLink.getUrl() ).endTag( NAMESPACE, "url" );
362 }
363 if ( offlineLink.getLocation() != null )
364 {
365 serializer.startTag( NAMESPACE, "location" ).text( offlineLink.getLocation() ).endTag( NAMESPACE, "location" );
366 }
367 serializer.endTag( NAMESPACE, tagName );
368 }
369
370
371
372
373
374
375
376
377
378 private void writeResourcesArtifact( ResourcesArtifact resourcesArtifact, String tagName, XmlSerializer serializer )
379 throws java.io.IOException
380 {
381 serializer.startTag( NAMESPACE, tagName );
382 if ( resourcesArtifact.getGroupId() != null )
383 {
384 serializer.startTag( NAMESPACE, "groupId" ).text( resourcesArtifact.getGroupId() ).endTag( NAMESPACE, "groupId" );
385 }
386 if ( resourcesArtifact.getArtifactId() != null )
387 {
388 serializer.startTag( NAMESPACE, "artifactId" ).text( resourcesArtifact.getArtifactId() ).endTag( NAMESPACE, "artifactId" );
389 }
390 if ( resourcesArtifact.getVersion() != null )
391 {
392 serializer.startTag( NAMESPACE, "version" ).text( resourcesArtifact.getVersion() ).endTag( NAMESPACE, "version" );
393 }
394 if ( resourcesArtifact.getClassifier() != null )
395 {
396 serializer.startTag( NAMESPACE, "classifier" ).text( resourcesArtifact.getClassifier() ).endTag( NAMESPACE, "classifier" );
397 }
398 serializer.endTag( NAMESPACE, tagName );
399 }
400
401
402
403
404
405
406
407
408
409 private void writeTag( Tag tag, String tagName, XmlSerializer serializer )
410 throws java.io.IOException
411 {
412 serializer.startTag( NAMESPACE, tagName );
413 if ( tag.getName() != null )
414 {
415 serializer.startTag( NAMESPACE, "name" ).text( tag.getName() ).endTag( NAMESPACE, "name" );
416 }
417 if ( tag.getHead() != null )
418 {
419 serializer.startTag( NAMESPACE, "head" ).text( tag.getHead() ).endTag( NAMESPACE, "head" );
420 }
421 if ( tag.getPlacement() != null )
422 {
423 serializer.startTag( NAMESPACE, "placement" ).text( tag.getPlacement() ).endTag( NAMESPACE, "placement" );
424 }
425 serializer.endTag( NAMESPACE, tagName );
426 }
427
428
429
430
431
432
433
434
435
436 private void writeTaglet( Taglet taglet, String tagName, XmlSerializer serializer )
437 throws java.io.IOException
438 {
439 serializer.startTag( NAMESPACE, tagName );
440 if ( taglet.getTagletClass() != null )
441 {
442 serializer.startTag( NAMESPACE, "tagletClass" ).text( taglet.getTagletClass() ).endTag( NAMESPACE, "tagletClass" );
443 }
444 if ( taglet.getTagletpath() != null )
445 {
446 serializer.startTag( NAMESPACE, "tagletpath" ).text( taglet.getTagletpath() ).endTag( NAMESPACE, "tagletpath" );
447 }
448 if ( taglet.getTagletArtifact() != null )
449 {
450 writeTagletArtifact( (TagletArtifact) taglet.getTagletArtifact(), "tagletArtifact", serializer );
451 }
452 serializer.endTag( NAMESPACE, tagName );
453 }
454
455
456
457
458
459
460
461
462
463 private void writeTagletArtifact( TagletArtifact tagletArtifact, String tagName, XmlSerializer serializer )
464 throws java.io.IOException
465 {
466 serializer.startTag( NAMESPACE, tagName );
467 if ( tagletArtifact.getGroupId() != null )
468 {
469 serializer.startTag( NAMESPACE, "groupId" ).text( tagletArtifact.getGroupId() ).endTag( NAMESPACE, "groupId" );
470 }
471 if ( tagletArtifact.getArtifactId() != null )
472 {
473 serializer.startTag( NAMESPACE, "artifactId" ).text( tagletArtifact.getArtifactId() ).endTag( NAMESPACE, "artifactId" );
474 }
475 if ( tagletArtifact.getVersion() != null )
476 {
477 serializer.startTag( NAMESPACE, "version" ).text( tagletArtifact.getVersion() ).endTag( NAMESPACE, "version" );
478 }
479 if ( tagletArtifact.getClassifier() != null )
480 {
481 serializer.startTag( NAMESPACE, "classifier" ).text( tagletArtifact.getClassifier() ).endTag( NAMESPACE, "classifier" );
482 }
483 serializer.endTag( NAMESPACE, tagName );
484 }
485
486 }