1
2
3
4
5 package org.apache.maven.usability.plugin.io.xpp3;
6
7
8
9
10
11 import java.io.Writer;
12 import java.text.DateFormat;
13 import java.util.Iterator;
14 import java.util.Locale;
15 import org.apache.maven.usability.plugin.Expression;
16 import org.apache.maven.usability.plugin.ExpressionDocumentation;
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 public class ParamdocXpp3Writer {
26
27
28
29
30
31
32
33
34
35 private String NAMESPACE;
36
37
38
39
40
41
42
43
44
45
46
47
48
49 public void write( Writer writer, ExpressionDocumentation expressionDocumentation )
50 throws java.io.IOException
51 {
52 XmlSerializer serializer = new MXSerializer();
53 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " );
54 serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
55 serializer.setOutput( writer );
56 serializer.startDocument( expressionDocumentation.getModelEncoding(), null );
57 writeExpressionDocumentation( expressionDocumentation, "paramdoc", serializer );
58 serializer.endDocument();
59 }
60
61
62
63
64
65
66
67
68
69 private void writeExpression( Expression expression, String tagName, XmlSerializer serializer )
70 throws java.io.IOException
71 {
72 if ( expression != null )
73 {
74 serializer.startTag( NAMESPACE, tagName );
75 if ( expression.getSyntax() != null )
76 {
77 serializer.startTag( NAMESPACE, "syntax" ).text( expression.getSyntax() ).endTag( NAMESPACE, "syntax" );
78 }
79 if ( expression.getDescription() != null )
80 {
81 serializer.startTag( NAMESPACE, "description" ).text( expression.getDescription() ).endTag( NAMESPACE, "description" );
82 }
83 if ( expression.getConfiguration() != null )
84 {
85 serializer.startTag( NAMESPACE, "configuration" ).text( expression.getConfiguration() ).endTag( NAMESPACE, "configuration" );
86 }
87 if ( expression.getCliOptions() != null && expression.getCliOptions().size() > 0 )
88 {
89 serializer.startTag( NAMESPACE, "cliOptions" );
90 for ( Iterator iter = expression.getCliOptions().keySet().iterator(); iter.hasNext(); )
91 {
92 String key = (String) iter.next();
93 String value = (String) expression.getCliOptions().get( key );
94 serializer.startTag( NAMESPACE, "cliOption" );
95 serializer.startTag( NAMESPACE, "key" ).text( key ).endTag( NAMESPACE, "key" );
96 serializer.startTag( NAMESPACE, "value" ).text( value ).endTag( NAMESPACE, "value" );
97 serializer.endTag( NAMESPACE, "cliOption" );
98 }
99 serializer.endTag( NAMESPACE, "cliOptions" );
100 }
101 if ( expression.getApiMethods() != null && expression.getApiMethods().size() > 0 )
102 {
103 serializer.startTag( NAMESPACE, "apiMethods" );
104 for ( Iterator iter = expression.getApiMethods().keySet().iterator(); iter.hasNext(); )
105 {
106 String key = (String) iter.next();
107 String value = (String) expression.getApiMethods().get( key );
108 serializer.startTag( NAMESPACE, "apiMethod" );
109 serializer.startTag( NAMESPACE, "key" ).text( key ).endTag( NAMESPACE, "key" );
110 serializer.startTag( NAMESPACE, "value" ).text( value ).endTag( NAMESPACE, "value" );
111 serializer.endTag( NAMESPACE, "apiMethod" );
112 }
113 serializer.endTag( NAMESPACE, "apiMethods" );
114 }
115 if ( expression.getDeprecation() != null )
116 {
117 serializer.startTag( NAMESPACE, "deprecation" ).text( expression.getDeprecation() ).endTag( NAMESPACE, "deprecation" );
118 }
119 if ( expression.getBan() != null )
120 {
121 serializer.startTag( NAMESPACE, "ban" ).text( expression.getBan() ).endTag( NAMESPACE, "ban" );
122 }
123 if ( expression.isEditable() != true )
124 {
125 serializer.startTag( NAMESPACE, "editable" ).text( String.valueOf( expression.isEditable() ) ).endTag( NAMESPACE, "editable" );
126 }
127 serializer.endTag( NAMESPACE, tagName );
128 }
129 }
130
131
132
133
134
135
136
137
138
139 private void writeExpressionDocumentation( ExpressionDocumentation expressionDocumentation, String tagName, XmlSerializer serializer )
140 throws java.io.IOException
141 {
142 if ( expressionDocumentation != null )
143 {
144 serializer.startTag( NAMESPACE, tagName );
145 if ( expressionDocumentation.getExpressions() != null && expressionDocumentation.getExpressions().size() > 0 )
146 {
147 serializer.startTag( NAMESPACE, "expressions" );
148 for ( Iterator iter = expressionDocumentation.getExpressions().iterator(); iter.hasNext(); )
149 {
150 Expression o = (Expression) iter.next();
151 writeExpression( o, "expression", serializer );
152 }
153 serializer.endTag( NAMESPACE, "expressions" );
154 }
155 serializer.endTag( NAMESPACE, tagName );
156 }
157 }
158
159
160 }