1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
package org.apache.maven.archetype.registry.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.archetype.registry.ArchetypeRegistry; |
20 | |
import org.codehaus.plexus.util.xml.pull.MXSerializer; |
21 | |
import org.codehaus.plexus.util.xml.pull.XmlSerializer; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
@SuppressWarnings( "all" ) |
29 | 0 | public class ArchetypeRegistryXpp3Writer |
30 | |
{ |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 0 | private static final String NAMESPACE = null; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
public void write( Writer writer, ArchetypeRegistry archetypeRegistry ) |
54 | |
throws java.io.IOException |
55 | |
{ |
56 | 0 | XmlSerializer serializer = new MXSerializer(); |
57 | 0 | serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " ); |
58 | 0 | serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" ); |
59 | 0 | serializer.setOutput( writer ); |
60 | 0 | serializer.startDocument( archetypeRegistry.getModelEncoding(), null ); |
61 | 0 | writeArchetypeRegistry( archetypeRegistry, "archetype-registry", serializer ); |
62 | 0 | serializer.endDocument(); |
63 | 0 | } |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
public void write( OutputStream stream, ArchetypeRegistry archetypeRegistry ) |
73 | |
throws java.io.IOException |
74 | |
{ |
75 | 0 | XmlSerializer serializer = new MXSerializer(); |
76 | 0 | serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " ); |
77 | 0 | serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" ); |
78 | 0 | serializer.setOutput( stream, archetypeRegistry.getModelEncoding() ); |
79 | 0 | serializer.startDocument( archetypeRegistry.getModelEncoding(), null ); |
80 | 0 | writeArchetypeRegistry( archetypeRegistry, "archetype-registry", serializer ); |
81 | 0 | serializer.endDocument(); |
82 | 0 | } |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
private void writeArchetypeRegistry( ArchetypeRegistry archetypeRegistry, String tagName, XmlSerializer serializer ) |
93 | |
throws java.io.IOException |
94 | |
{ |
95 | 0 | serializer.setPrefix( "", "http://maven.apache.org/plugins/maven-archetype-plugin/archetype-registry/1.0.0" ); |
96 | 0 | serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" ); |
97 | 0 | serializer.startTag( NAMESPACE, tagName ); |
98 | 0 | serializer.attribute( "", "xsi:schemaLocation", "http://maven.apache.org/plugins/maven-archetype-plugin/archetype-registry/1.0.0 http://maven.apache.org/xsd/archetype-registry-1.0.0.xsd" ); |
99 | 0 | if ( ( archetypeRegistry.getLanguages() != null ) && ( archetypeRegistry.getLanguages().size() > 0 ) ) |
100 | |
{ |
101 | 0 | serializer.startTag( NAMESPACE, "Languages" ); |
102 | 0 | for ( Iterator iter = archetypeRegistry.getLanguages().iterator(); iter.hasNext(); ) |
103 | |
{ |
104 | 0 | String language = (String) iter.next(); |
105 | 0 | serializer.startTag( NAMESPACE, "Language" ).text( language ).endTag( NAMESPACE, "Language" ); |
106 | 0 | } |
107 | 0 | serializer.endTag( NAMESPACE, "Languages" ); |
108 | |
} |
109 | 0 | if ( ( archetypeRegistry.getFilteredExtensions() != null ) && ( archetypeRegistry.getFilteredExtensions().size() > 0 ) ) |
110 | |
{ |
111 | 0 | serializer.startTag( NAMESPACE, "FilteredExtensions" ); |
112 | 0 | for ( Iterator iter = archetypeRegistry.getFilteredExtensions().iterator(); iter.hasNext(); ) |
113 | |
{ |
114 | 0 | String filteredExtension = (String) iter.next(); |
115 | 0 | serializer.startTag( NAMESPACE, "FilteredExtension" ).text( filteredExtension ).endTag( NAMESPACE, "FilteredExtension" ); |
116 | 0 | } |
117 | 0 | serializer.endTag( NAMESPACE, "FilteredExtensions" ); |
118 | |
} |
119 | 0 | serializer.endTag( NAMESPACE, tagName ); |
120 | 0 | } |
121 | |
|
122 | |
} |