1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
package org.apache.maven.archetype.catalog.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.catalog.Archetype; |
20 | |
import org.apache.maven.archetype.catalog.ArchetypeCatalog; |
21 | |
import org.codehaus.plexus.util.xml.pull.MXSerializer; |
22 | |
import org.codehaus.plexus.util.xml.pull.XmlSerializer; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
@SuppressWarnings( "all" ) |
30 | 6 | public class ArchetypeCatalogXpp3Writer |
31 | |
{ |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 1 | private static final String NAMESPACE = null; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
public void write( Writer writer, ArchetypeCatalog archetypeCatalog ) |
55 | |
throws java.io.IOException |
56 | |
{ |
57 | 6 | XmlSerializer serializer = new MXSerializer(); |
58 | 6 | serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " ); |
59 | 6 | serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" ); |
60 | 6 | serializer.setOutput( writer ); |
61 | 6 | serializer.startDocument( archetypeCatalog.getModelEncoding(), null ); |
62 | 6 | writeArchetypeCatalog( archetypeCatalog, "archetype-catalog", serializer ); |
63 | 6 | serializer.endDocument(); |
64 | 6 | } |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
public void write( OutputStream stream, ArchetypeCatalog archetypeCatalog ) |
74 | |
throws java.io.IOException |
75 | |
{ |
76 | 0 | XmlSerializer serializer = new MXSerializer(); |
77 | 0 | serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " ); |
78 | 0 | serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" ); |
79 | 0 | serializer.setOutput( stream, archetypeCatalog.getModelEncoding() ); |
80 | 0 | serializer.startDocument( archetypeCatalog.getModelEncoding(), null ); |
81 | 0 | writeArchetypeCatalog( archetypeCatalog, "archetype-catalog", serializer ); |
82 | 0 | serializer.endDocument(); |
83 | 0 | } |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
private void writeArchetype( Archetype archetype, String tagName, XmlSerializer serializer ) |
94 | |
throws java.io.IOException |
95 | |
{ |
96 | 6 | serializer.startTag( NAMESPACE, tagName ); |
97 | 6 | if ( archetype.getGroupId() != null ) |
98 | |
{ |
99 | 6 | serializer.startTag( NAMESPACE, "groupId" ).text( archetype.getGroupId() ).endTag( NAMESPACE, "groupId" ); |
100 | |
} |
101 | 6 | if ( archetype.getArtifactId() != null ) |
102 | |
{ |
103 | 6 | serializer.startTag( NAMESPACE, "artifactId" ).text( archetype.getArtifactId() ).endTag( NAMESPACE, "artifactId" ); |
104 | |
} |
105 | 6 | if ( archetype.getVersion() != null ) |
106 | |
{ |
107 | 6 | serializer.startTag( NAMESPACE, "version" ).text( archetype.getVersion() ).endTag( NAMESPACE, "version" ); |
108 | |
} |
109 | 6 | if ( archetype.getRepository() != null ) |
110 | |
{ |
111 | 6 | serializer.startTag( NAMESPACE, "repository" ).text( archetype.getRepository() ).endTag( NAMESPACE, "repository" ); |
112 | |
} |
113 | 6 | if ( archetype.getDescription() != null ) |
114 | |
{ |
115 | 1 | serializer.startTag( NAMESPACE, "description" ).text( archetype.getDescription() ).endTag( NAMESPACE, "description" ); |
116 | |
} |
117 | 6 | serializer.endTag( NAMESPACE, tagName ); |
118 | 6 | } |
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
private void writeArchetypeCatalog( ArchetypeCatalog archetypeCatalog, String tagName, XmlSerializer serializer ) |
129 | |
throws java.io.IOException |
130 | |
{ |
131 | 6 | serializer.setPrefix( "", "http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0" ); |
132 | 6 | serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" ); |
133 | 6 | serializer.startTag( NAMESPACE, tagName ); |
134 | 6 | serializer.attribute( "", "xsi:schemaLocation", "http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0 http://maven.apache.org/xsd/archetype-catalog-1.0.0.xsd" ); |
135 | 6 | if ( ( archetypeCatalog.getArchetypes() != null ) && ( archetypeCatalog.getArchetypes().size() > 0 ) ) |
136 | |
{ |
137 | 6 | serializer.startTag( NAMESPACE, "archetypes" ); |
138 | 6 | for ( Iterator iter = archetypeCatalog.getArchetypes().iterator(); iter.hasNext(); ) |
139 | |
{ |
140 | 6 | Archetype o = (Archetype) iter.next(); |
141 | 6 | writeArchetype( o, "archetype", serializer ); |
142 | 6 | } |
143 | 6 | serializer.endTag( NAMESPACE, "archetypes" ); |
144 | |
} |
145 | 6 | serializer.endTag( NAMESPACE, tagName ); |
146 | 6 | } |
147 | |
|
148 | |
} |