1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.apache.maven.usability.plugin.io.xpp3;
25
26
27
28
29
30 import java.io.OutputStream;
31 import java.io.Writer;
32 import java.util.Iterator;
33 import org.apache.maven.usability.plugin.Expression;
34 import org.apache.maven.usability.plugin.ExpressionDocumentation;
35 import org.codehaus.plexus.util.xml.pull.MXSerializer;
36 import org.codehaus.plexus.util.xml.pull.XmlSerializer;
37
38
39
40
41
42
43 @SuppressWarnings( "all" )
44 public class ParamdocXpp3Writer
45 {
46
47
48
49
50
51
52
53
54 private static final String NAMESPACE = null;
55
56
57
58
59 private String fileComment = null;
60
61
62
63
64
65
66
67
68
69
70
71 public void setFileComment( String fileComment )
72 {
73 this.fileComment = fileComment;
74 }
75
76
77
78
79
80
81
82
83
84 public void write( Writer writer, ExpressionDocumentation expressionDocumentation )
85 throws java.io.IOException
86 {
87 XmlSerializer serializer = new MXSerializer();
88 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " );
89 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
90 serializer.setOutput( writer );
91 serializer.startDocument( expressionDocumentation.getModelEncoding(), null );
92 writeExpressionDocumentation( expressionDocumentation, "paramdoc", serializer );
93 serializer.endDocument();
94 }
95
96
97
98
99
100
101
102
103
104 public void write( OutputStream stream, ExpressionDocumentation expressionDocumentation )
105 throws java.io.IOException
106 {
107 XmlSerializer serializer = new MXSerializer();
108 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " );
109 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
110 serializer.setOutput( stream, expressionDocumentation.getModelEncoding() );
111 serializer.startDocument( expressionDocumentation.getModelEncoding(), null );
112 writeExpressionDocumentation( expressionDocumentation, "paramdoc", serializer );
113 serializer.endDocument();
114 }
115
116
117
118
119
120
121
122
123
124 private void writeExpression( Expression expression, String tagName, XmlSerializer serializer )
125 throws java.io.IOException
126 {
127 serializer.startTag( NAMESPACE, tagName );
128 if ( expression.getSyntax() != null )
129 {
130 serializer.startTag( NAMESPACE, "syntax" ).text( expression.getSyntax() ).endTag( NAMESPACE, "syntax" );
131 }
132 if ( expression.getDescription() != null )
133 {
134 serializer.startTag( NAMESPACE, "description" ).text( expression.getDescription() ).endTag( NAMESPACE, "description" );
135 }
136 if ( expression.getConfiguration() != null )
137 {
138 serializer.startTag( NAMESPACE, "configuration" ).text( expression.getConfiguration() ).endTag( NAMESPACE, "configuration" );
139 }
140 if ( ( expression.getCliOptions() != null ) && ( expression.getCliOptions().size() > 0 ) )
141 {
142 serializer.startTag( NAMESPACE, "cliOptions" );
143 for ( Iterator iter = expression.getCliOptions().keySet().iterator(); iter.hasNext(); )
144 {
145 String key = (String) iter.next();
146 String value = (String) expression.getCliOptions().get( key );
147 serializer.startTag( NAMESPACE, "cliOption" );
148 serializer.startTag( NAMESPACE, "key" ).text( key ).endTag( NAMESPACE, "key" );
149 serializer.startTag( NAMESPACE, "value" ).text( value ).endTag( NAMESPACE, "value" );
150 serializer.endTag( NAMESPACE, "cliOption" );
151 }
152 serializer.endTag( NAMESPACE, "cliOptions" );
153 }
154 if ( ( expression.getApiMethods() != null ) && ( expression.getApiMethods().size() > 0 ) )
155 {
156 serializer.startTag( NAMESPACE, "apiMethods" );
157 for ( Iterator iter = expression.getApiMethods().keySet().iterator(); iter.hasNext(); )
158 {
159 String key = (String) iter.next();
160 String value = (String) expression.getApiMethods().get( key );
161 serializer.startTag( NAMESPACE, "apiMethod" );
162 serializer.startTag( NAMESPACE, "key" ).text( key ).endTag( NAMESPACE, "key" );
163 serializer.startTag( NAMESPACE, "value" ).text( value ).endTag( NAMESPACE, "value" );
164 serializer.endTag( NAMESPACE, "apiMethod" );
165 }
166 serializer.endTag( NAMESPACE, "apiMethods" );
167 }
168 if ( expression.getDeprecation() != null )
169 {
170 serializer.startTag( NAMESPACE, "deprecation" ).text( expression.getDeprecation() ).endTag( NAMESPACE, "deprecation" );
171 }
172 if ( expression.getBan() != null )
173 {
174 serializer.startTag( NAMESPACE, "ban" ).text( expression.getBan() ).endTag( NAMESPACE, "ban" );
175 }
176 if ( expression.isEditable() != true )
177 {
178 serializer.startTag( NAMESPACE, "editable" ).text( String.valueOf( expression.isEditable() ) ).endTag( NAMESPACE, "editable" );
179 }
180 serializer.endTag( NAMESPACE, tagName );
181 }
182
183
184
185
186
187
188
189
190
191
192 private void writeExpressionDocumentation( ExpressionDocumentation expressionDocumentation, String tagName, XmlSerializer serializer )
193 throws java.io.IOException
194 {
195 if ( this.fileComment != null )
196 {
197 serializer.comment(this.fileComment);
198 }
199 serializer.setPrefix( "", "http://maven.apache.org/PARAMDOC/1.0.0" );
200 serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
201 serializer.startTag( NAMESPACE, tagName );
202 serializer.attribute( "", "xsi:schemaLocation", "http://maven.apache.org/PARAMDOC/1.0.0 http://maven.apache.org/xsd/paramdoc-1.0.0.xsd" );
203 if ( ( expressionDocumentation.getExpressions() != null ) && ( expressionDocumentation.getExpressions().size() > 0 ) )
204 {
205 serializer.startTag( NAMESPACE, "expressions" );
206 for ( Iterator iter = expressionDocumentation.getExpressions().iterator(); iter.hasNext(); )
207 {
208 Expression o = (Expression) iter.next();
209 writeExpression( o, "expression", serializer );
210 }
211 serializer.endTag( NAMESPACE, "expressions" );
212 }
213 serializer.endTag( NAMESPACE, tagName );
214 }
215
216 }