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