1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
package org.apache.maven.toolchain.model.io.xpp3; |
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
import java.io.Writer; |
15 | |
import java.text.DateFormat; |
16 | |
import java.util.Iterator; |
17 | |
import java.util.Locale; |
18 | |
import org.apache.maven.toolchain.model.PersistedToolchains; |
19 | |
import org.apache.maven.toolchain.model.ToolchainModel; |
20 | |
import org.codehaus.plexus.util.xml.Xpp3Dom; |
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 | 0 | public class MavenToolchainsXpp3Writer |
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, PersistedToolchains persistedToolchains ) |
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( persistedToolchains.getModelEncoding(), null ); |
61 | 0 | writePersistedToolchains( persistedToolchains, "toolchains", serializer ); |
62 | 0 | serializer.endDocument(); |
63 | 0 | } |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
private void writePersistedToolchains( PersistedToolchains persistedToolchains, String tagName, XmlSerializer serializer ) |
74 | |
throws java.io.IOException |
75 | |
{ |
76 | 0 | if ( persistedToolchains != null ) |
77 | |
{ |
78 | 0 | serializer.setPrefix( "", "http://maven.apache.org/TOOLCHAINS/1.0.0" ); |
79 | 0 | serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" ); |
80 | 0 | serializer.startTag( NAMESPACE, tagName ); |
81 | 0 | serializer.attribute( "", "xsi:schemaLocation", "http://maven.apache.org/TOOLCHAINS/1.0.0 http://maven.apache.org/xsd/toolchains-1.0.0.xsd" ); |
82 | 0 | if ( ( persistedToolchains.getToolchains() != null ) && ( persistedToolchains.getToolchains().size() > 0 ) ) |
83 | |
{ |
84 | 0 | for ( Iterator iter = persistedToolchains.getToolchains().iterator(); iter.hasNext(); ) |
85 | |
{ |
86 | 0 | ToolchainModel o = (ToolchainModel) iter.next(); |
87 | 0 | writeToolchainModel( o, "toolchain", serializer ); |
88 | 0 | } |
89 | |
} |
90 | 0 | serializer.endTag( NAMESPACE, tagName ); |
91 | |
} |
92 | 0 | } |
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
private void writeToolchainModel( ToolchainModel toolchainModel, String tagName, XmlSerializer serializer ) |
103 | |
throws java.io.IOException |
104 | |
{ |
105 | 0 | if ( toolchainModel != null ) |
106 | |
{ |
107 | 0 | serializer.startTag( NAMESPACE, tagName ); |
108 | 0 | if ( toolchainModel.getType() != null ) |
109 | |
{ |
110 | 0 | serializer.startTag( NAMESPACE, "type" ).text( toolchainModel.getType() ).endTag( NAMESPACE, "type" ); |
111 | |
} |
112 | 0 | if ( toolchainModel.getProvides() != null ) |
113 | |
{ |
114 | 0 | ((Xpp3Dom) toolchainModel.getProvides()).writeToSerializer( NAMESPACE, serializer ); |
115 | |
} |
116 | 0 | if ( toolchainModel.getConfiguration() != null ) |
117 | |
{ |
118 | 0 | ((Xpp3Dom) toolchainModel.getConfiguration()).writeToSerializer( NAMESPACE, serializer ); |
119 | |
} |
120 | 0 | serializer.endTag( NAMESPACE, tagName ); |
121 | |
} |
122 | 0 | } |
123 | |
|
124 | |
|
125 | |
} |