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.impl.AbstractSinkTest;
24 import org.apache.maven.doxia.sink.impl.SinkEventAttributeSet;
25
26 import java.io.StringWriter;
27 import java.io.Writer;
28
29 import static org.apache.maven.doxia.util.HtmlTools.escapeHTML;
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 https://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 getArticleBlock()
92 {
93 return "";
94 }
95
96
97 protected String getNavigationBlock()
98 {
99 return "";
100 }
101
102
103 protected String getSidebarBlock()
104 {
105 return "";
106 }
107
108
109 protected String getSectionTitleBlock( String title )
110 {
111 return title;
112 }
113
114
115 protected String getSection1Block( String title )
116 {
117 return "<section name=\"" + title + "\"></section>";
118 }
119
120
121 protected String getSection2Block( String title )
122 {
123 return "<subsection name=\"" + title + "\"></subsection>";
124 }
125
126
127 protected String getSection3Block( String title )
128 {
129 return "<h4>" + title + "</h4>";
130 }
131
132
133 protected String getSection4Block( String title )
134 {
135 return "<h5>" + title + "</h5>";
136 }
137
138
139 protected String getSection5Block( String title )
140 {
141 return "<h6>" + title + "</h6>";
142 }
143
144
145 protected String getHeaderBlock()
146 {
147 return "";
148 }
149
150
151 protected String getContentBlock()
152 {
153 return "";
154 }
155
156
157 protected String getFooterBlock()
158 {
159 return "";
160 }
161
162
163 protected String getListBlock( String item )
164 {
165 return "<ul>\n<li>" + item + "</li></ul>";
166 }
167
168
169 protected String getNumberedListBlock( String item )
170 {
171 return "<ol style=\"list-style-type: lower-roman\">\n<li>" + item + "</li></ol>";
172 }
173
174
175 protected String getDefinitionListBlock( String definum, String definition )
176 {
177 return "<dl>\n<dt>" + definum + "</dt>\n<dd>" + definition + "</dd></dl>";
178 }
179
180
181 protected String getFigureBlock( String source, String caption )
182 {
183 String figureBlock = "<img src=\"" + escapeHTML( source ) + "\"";
184 if ( caption != null )
185 {
186 figureBlock += " alt=\"" + caption + "\"";
187 }
188 else
189 {
190 figureBlock += " alt=\"\"";
191 }
192 figureBlock += " />";
193 return figureBlock;
194 }
195
196
197 protected String getTableBlock( String cell, String caption )
198 {
199 return "<table border=\"0\"><caption>" + caption
200 + "</caption>\n<tr valign=\"top\">\n<td align=\"center\">" + cell + "</td></tr></table>";
201 }
202
203
204 protected String getParagraphBlock( String text )
205 {
206 return "<p>" + text + "</p>";
207 }
208
209
210 protected String getDataBlock( String value, String text )
211 {
212 return text;
213 }
214
215
216 protected String getTimeBlock( String datetime, String text )
217 {
218 return text;
219 }
220
221
222 protected String getAddressBlock( String text )
223 {
224 return "<address>" + text + "</address>";
225 }
226
227
228 protected String getBlockquoteBlock( String text )
229 {
230 return "<blockquote>" + text + "</blockquote>";
231 }
232
233
234 protected String getDivisionBlock( String text )
235 {
236 return "<div>" + text + "</div>";
237 }
238
239
240 protected String getVerbatimBlock( String text )
241 {
242 return "<source>" + text + "</source>";
243 }
244
245
246 protected String getHorizontalRuleBlock()
247 {
248 return "<hr />";
249 }
250
251
252 protected String getPageBreakBlock()
253 {
254 return "<!-- PB -->";
255 }
256
257
258 protected String getAnchorBlock( String anchor )
259 {
260 return "<a name=\"" + anchor + "\">" + anchor + "</a>";
261 }
262
263
264 protected String getLinkBlock( String link, String text )
265 {
266 return "<a href=\"" + link + "\">" + text + "</a>";
267 }
268
269
270 protected String getInlineBlock( String text )
271 {
272 return text;
273 }
274
275
276 protected String getInlineItalicBlock( String text )
277 {
278 return "<i>" + text + "</i>";
279 }
280
281
282 protected String getInlineBoldBlock( String text )
283 {
284 return "<b>" + text + "</b>";
285 }
286
287
288 protected String getInlineCodeBlock( String text )
289 {
290 return "<code>" + text + "</code>";
291 }
292
293
294 protected String getItalicBlock( String text )
295 {
296 return "<i>" + text + "</i>";
297 }
298
299
300 protected String getBoldBlock( String text )
301 {
302 return "<b>" + text + "</b>";
303 }
304
305
306 protected String getMonospacedBlock( String text )
307 {
308 return "<tt>" + text + "</tt>";
309 }
310
311
312 protected String getLineBreakBlock()
313 {
314 return "<br />";
315 }
316
317
318 protected String getLineBreakOpportunityBlock()
319 {
320 return "";
321 }
322
323
324 protected String getNonBreakingSpaceBlock()
325 {
326 return " ";
327 }
328
329
330 protected String getTextBlock( String text )
331 {
332
333 return escapeHTML( text );
334 }
335
336
337 protected String getRawTextBlock( String text )
338 {
339 return "~,_=,_-,_+,_*,_[,_],_<,_>,_{,_},_\\";
340 }
341
342
343
344
345 public void testBoxedVerbatim()
346 {
347 Writer writer = new StringWriter();
348 XdocSink sink = null;
349
350 try
351 {
352 sink = new XdocSink( writer );
353
354 sink.verbatim( null );
355 sink.verbatim_();
356 sink.verbatim( SinkEventAttributeSet.BOXED );
357 sink.verbatim_();
358 sink.verbatim( new SinkEventAttributeSet( SinkEventAttributeSet.WIDTH, "20%" ) );
359 sink.verbatim_();
360 }
361 finally
362 {
363 sink.close();
364 }
365
366 assertEquals( "<pre></pre><source></source>\n<pre width=\"20%\"></pre>", writer.toString() );
367 }
368
369
370
371
372 public void testLinkWithTarget()
373 {
374 Writer writer = new StringWriter();
375 XdocSink sink = null;
376
377 try
378 {
379 sink = new XdocSink( writer );
380
381 sink.link( "name", (String) null );
382 sink.link_();
383 sink.link( "name", "nirvana" );
384 sink.link_();
385 }
386 finally
387 {
388 sink.close();
389 }
390
391 assertEquals( "<a href=\"name\"></a><a href=\"name\" target=\"nirvana\"></a>", writer.toString() );
392 }
393
394
395 protected String getCommentBlock( String text )
396 {
397 return "<!--" + toXmlComment( text ) + "-->";
398 }
399 }