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