1 package org.apache.maven.doxia.module.xdoc;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.doxia.sink.Sink;
23 import org.apache.maven.doxia.sink.AbstractSinkTest;
24 import org.apache.maven.doxia.util.HtmlTools;
25
26 import java.io.StringWriter;
27 import java.io.Writer;
28 import org.apache.maven.doxia.sink.SinkEventAttributeSet;
29
30
31
32
33
34
35 public class XdocSinkTest
36 extends AbstractSinkTest
37 {
38
39 protected String outputExtension()
40 {
41 return "xml";
42 }
43
44
45 protected Sink createSink( Writer writer )
46 {
47 return new XdocSink( writer, "UTF-8" );
48 }
49
50
51 protected boolean isXmlSink()
52 {
53 return true;
54 }
55
56
57 protected String getTitleBlock( String title )
58 {
59 return "<title>" + title + "</title>";
60 }
61
62
63 protected String getAuthorBlock( String author )
64 {
65 return author;
66 }
67
68
69 protected String getDateBlock( String date )
70 {
71 return date;
72 }
73
74
75 protected String getHeadBlock()
76 {
77 return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
78 + "<document xmlns=\"http://maven.apache.org/XDOC/2.0\" "
79 + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
80 + "xsi:schemaLocation=\"http://maven.apache.org/XDOC/2.0 http://maven.apache.org/xsd/xdoc-2.0.xsd\">"
81 + "<properties></properties>";
82 }
83
84
85 protected String getBodyBlock()
86 {
87 return "<body></body></document>";
88 }
89
90
91 protected String getSectionTitleBlock( String title )
92 {
93 return title;
94 }
95
96
97 protected String getSection1Block( String title )
98 {
99 return "<section name=\"" + title + "\"></section>";
100 }
101
102
103 protected String getSection2Block( String title )
104 {
105 return "<subsection name=\"" + title + "\"></subsection>";
106 }
107
108
109 protected String getSection3Block( String title )
110 {
111 return "<h4>" + title + "</h4>";
112 }
113
114
115 protected String getSection4Block( String title )
116 {
117 return "<h5>" + title + "</h5>";
118 }
119
120
121 protected String getSection5Block( String title )
122 {
123 return "<h6>" + title + "</h6>";
124 }
125
126
127 protected String getListBlock( String item )
128 {
129 return "<ul>\n<li>" + item + "</li></ul>";
130 }
131
132
133 protected String getNumberedListBlock( String item )
134 {
135 return "<ol style=\"list-style-type: lower-roman\">\n<li>" + item + "</li></ol>";
136 }
137
138
139 protected String getDefinitionListBlock( String definum, String definition )
140 {
141 return "<dl>\n<dt>" + definum + "</dt>\n<dd>" + definition + "</dd></dl>";
142 }
143
144
145 protected String getFigureBlock( String source, String caption )
146 {
147 String figureBlock = "<img src=\"" + source + "\"";
148 if ( caption != null )
149 {
150 figureBlock += " alt=\"" + caption + "\"";
151 }
152 else
153 {
154 figureBlock += " alt=\"\"";
155 }
156 figureBlock += " />";
157 return figureBlock;
158 }
159
160
161 protected String getTableBlock( String cell, String caption )
162 {
163 return "<table border=\"0\"><caption>" + caption
164 + "</caption>\n<tr valign=\"top\">\n<td>" + cell + "</td></tr></table>";
165 }
166
167
168 protected String getParagraphBlock( String text )
169 {
170 return "<p>" + text + "</p>";
171 }
172
173
174 protected String getVerbatimBlock( String text )
175 {
176 return "<source>" + text + "</source>";
177 }
178
179
180 protected String getHorizontalRuleBlock()
181 {
182 return "<hr />";
183 }
184
185
186 protected String getPageBreakBlock()
187 {
188 return "<!-- PB -->";
189 }
190
191
192 protected String getAnchorBlock( String anchor )
193 {
194 return "<a name=\"" + anchor + "\">" + anchor + "</a>";
195 }
196
197
198 protected String getLinkBlock( String link, String text )
199 {
200 return "<a href=\"" + link + "\">" + text + "</a>";
201 }
202
203
204 protected String getItalicBlock( String text )
205 {
206 return "<i>" + text + "</i>";
207 }
208
209
210 protected String getBoldBlock( String text )
211 {
212 return "<b>" + text + "</b>";
213 }
214
215
216 protected String getMonospacedBlock( String text )
217 {
218 return "<tt>" + text + "</tt>";
219 }
220
221
222 protected String getLineBreakBlock()
223 {
224 return "<br />";
225 }
226
227
228 protected String getNonBreakingSpaceBlock()
229 {
230 return " ";
231 }
232
233
234 protected String getTextBlock( String text )
235 {
236
237 return HtmlTools.escapeHTML( text );
238 }
239
240
241 protected String getRawTextBlock( String text )
242 {
243 return "~,_=,_-,_+,_*,_[,_],_<,_>,_{,_},_\\";
244 }
245
246
247
248
249 public void testBoxedVerbatim()
250 {
251 Writer writer = new StringWriter();
252 XdocSink sink = null;
253
254 try
255 {
256 sink = new XdocSink( writer );
257
258 sink.verbatim( null );
259 sink.verbatim_();
260 sink.verbatim( SinkEventAttributeSet.BOXED );
261 sink.verbatim_();
262 sink.verbatim( new SinkEventAttributeSet( new String[] {SinkEventAttributeSet.WIDTH, "20%"} ) );
263 sink.verbatim_();
264 }
265 finally
266 {
267 sink.close();
268 }
269
270 assertEquals( "<pre></pre><source></source>\n<pre width=\"20%\"></pre>", writer.toString() );
271 }
272
273
274
275
276 public void testLinkWithTarget()
277 {
278 Writer writer = new StringWriter();
279 XdocSink sink = null;
280
281 try
282 {
283 sink = new XdocSink( writer );
284
285 sink.link( "name", (String) null );
286 sink.link_();
287 sink.link( "name", "nirvana" );
288 sink.link_();
289 }
290 finally
291 {
292 sink.close();
293 }
294
295 assertEquals( "<a href=\"name\"></a><a href=\"name\" target=\"nirvana\"></a>", writer.toString() );
296 }
297
298
299 protected String getCommentBlock( String text )
300 {
301 return "<!-- Simple comment with - - - - -->";
302 }
303 }