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 | 0 | public class ArchetypeCatalogXpp3Writer |
31 | |
{ |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 0 | 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 | 0 | XmlSerializer serializer = new MXSerializer(); |
58 | 0 | serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " ); |
59 | 0 | serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" ); |
60 | 0 | serializer.setOutput( writer ); |
61 | 0 | serializer.startDocument( archetypeCatalog.getModelEncoding(), null ); |
62 | 0 | writeArchetypeCatalog( archetypeCatalog, "archetype-catalog", serializer ); |
63 | 0 | serializer.endDocument(); |
64 | 0 | } |
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 | 0 | serializer.startTag( NAMESPACE, tagName ); |
97 | 0 | if ( archetype.getGroupId() != null ) |
98 | |
{ |
99 | 0 | serializer.startTag( NAMESPACE, "groupId" ).text( archetype.getGroupId() ).endTag( NAMESPACE, "groupId" ); |
100 | |
} |
101 | 0 | if ( archetype.getArtifactId() != null ) |
102 | |
{ |
103 | 0 | serializer.startTag( NAMESPACE, "artifactId" ).text( archetype.getArtifactId() ).endTag( NAMESPACE, "artifactId" ); |
104 | |
} |
105 | 0 | if ( archetype.getVersion() != null ) |
106 | |
{ |
107 | 0 | serializer.startTag( NAMESPACE, "version" ).text( archetype.getVersion() ).endTag( NAMESPACE, "version" ); |
108 | |
} |
109 | 0 | if ( archetype.getRepository() != null ) |
110 | |
{ |
111 | 0 | serializer.startTag( NAMESPACE, "repository" ).text( archetype.getRepository() ).endTag( NAMESPACE, "repository" ); |
112 | |
} |
113 | 0 | if ( archetype.getDescription() != null ) |
114 | |
{ |
115 | 0 | serializer.startTag( NAMESPACE, "description" ).text( archetype.getDescription() ).endTag( NAMESPACE, "description" ); |
116 | |
} |
117 | 0 | serializer.endTag( NAMESPACE, tagName ); |
118 | 0 | } |
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 | 0 | serializer.setPrefix( "", "http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0" ); |
132 | 0 | serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" ); |
133 | 0 | serializer.startTag( NAMESPACE, tagName ); |
134 | 0 | 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 | 0 | if ( ( archetypeCatalog.getArchetypes() != null ) && ( archetypeCatalog.getArchetypes().size() > 0 ) ) |
136 | |
{ |
137 | 0 | serializer.startTag( NAMESPACE, "archetypes" ); |
138 | 0 | for ( Iterator iter = archetypeCatalog.getArchetypes().iterator(); iter.hasNext(); ) |
139 | |
{ |
140 | 0 | Archetype o = (Archetype) iter.next(); |
141 | 0 | writeArchetype( o, "archetype", serializer ); |
142 | 0 | } |
143 | 0 | serializer.endTag( NAMESPACE, "archetypes" ); |
144 | |
} |
145 | 0 | serializer.endTag( NAMESPACE, tagName ); |
146 | 0 | } |
147 | |
|
148 | |
} |