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