1
2
3
4
5
6 package org.apache.maven.plugin.verifier.model.io.xpp3;
7
8
9
10
11
12 import java.io.OutputStream;
13 import java.io.Writer;
14 import java.util.Iterator;
15 import org.apache.maven.plugin.verifier.model.File;
16 import org.apache.maven.plugin.verifier.model.Verifications;
17 import org.codehaus.plexus.util.xml.pull.MXSerializer;
18 import org.codehaus.plexus.util.xml.pull.XmlSerializer;
19
20
21
22
23
24
25 @SuppressWarnings( "all" )
26 public class VerificationsXpp3Writer
27 {
28
29
30
31
32
33
34
35
36 private static final String NAMESPACE = null;
37
38
39
40
41
42
43
44
45
46
47
48
49
50 public void write( Writer writer, Verifications verifications )
51 throws java.io.IOException
52 {
53 XmlSerializer serializer = new MXSerializer();
54 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " );
55 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
56 serializer.setOutput( writer );
57 serializer.startDocument( verifications.getModelEncoding(), null );
58 writeVerifications( verifications, "verifications", serializer );
59 serializer.endDocument();
60 }
61
62
63
64
65
66
67
68
69 public void write( OutputStream stream, Verifications verifications )
70 throws java.io.IOException
71 {
72 XmlSerializer serializer = new MXSerializer();
73 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " );
74 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
75 serializer.setOutput( stream, verifications.getModelEncoding() );
76 serializer.startDocument( verifications.getModelEncoding(), null );
77 writeVerifications( verifications, "verifications", serializer );
78 serializer.endDocument();
79 }
80
81
82
83
84
85
86
87
88
89 private void writeFile( File file, String tagName, XmlSerializer serializer )
90 throws java.io.IOException
91 {
92 serializer.startTag( NAMESPACE, tagName );
93 if ( file.getLocation() != null )
94 {
95 serializer.startTag( NAMESPACE, "location" ).text( file.getLocation() ).endTag( NAMESPACE, "location" );
96 }
97 if ( file.getContains() != null )
98 {
99 serializer.startTag( NAMESPACE, "contains" ).text( file.getContains() ).endTag( NAMESPACE, "contains" );
100 }
101 if ( file.isExists() != true )
102 {
103 serializer.startTag( NAMESPACE, "exists" ).text( String.valueOf( file.isExists() ) ).endTag( NAMESPACE, "exists" );
104 }
105 serializer.endTag( NAMESPACE, tagName );
106 }
107
108
109
110
111
112
113
114
115
116 private void writeVerifications( Verifications verifications, String tagName, XmlSerializer serializer )
117 throws java.io.IOException
118 {
119 serializer.startTag( NAMESPACE, tagName );
120 if ( ( verifications.getFiles() != null ) && ( verifications.getFiles().size() > 0 ) )
121 {
122 serializer.startTag( NAMESPACE, "files" );
123 for ( Iterator iter = verifications.getFiles().iterator(); iter.hasNext(); )
124 {
125 File o = (File) iter.next();
126 writeFile( o, "file", serializer );
127 }
128 serializer.endTag( NAMESPACE, "files" );
129 }
130 serializer.endTag( NAMESPACE, tagName );
131 }
132
133 }