1 package org.apache.maven.doxia.module.xhtml;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.StringWriter;
23 import java.io.Writer;
24
25 import org.apache.maven.doxia.sink.AbstractSinkTest;
26 import org.apache.maven.doxia.sink.Sink;
27
28
29
30
31
32
33 public class XhtmlSinkTest
34 extends AbstractSinkTest
35 {
36
37 protected String outputExtension()
38 {
39 return "xhtml";
40 }
41
42
43 protected Sink createSink( Writer writer )
44 {
45 return new XhtmlSink( writer, "UTF-8" );
46 }
47
48
49 protected boolean isXmlSink()
50 {
51 return true;
52 }
53
54
55
56
57
58
59 public void testLinks()
60 throws Exception
61 {
62 XhtmlSink sink = null;
63 Writer writer = new StringWriter();
64 try
65 {
66 sink = (XhtmlSink) createSink( writer );
67 sink.link( "http:/www.xdoc.com" );
68 sink.link_();
69 sink.link( "./index.html#anchor" );
70 sink.link_();
71 sink.link( "../index.html#anchor" );
72 sink.link_();
73 sink.link( "index.html" );
74 sink.link_();
75 }
76 finally
77 {
78 if ( sink != null )
79 {
80 sink.close();
81 }
82 }
83
84 String actual = writer.toString();
85 assertTrue( actual.indexOf( "<a class=\"externalLink\" href=\"http:/www.xdoc.com\"></a>" ) != -1 );
86 assertTrue( actual.indexOf( "<a href=\"./index.html#anchor\"></a>" ) != -1 );
87 assertTrue( actual.indexOf( "<a href=\"../index.html#anchor\"></a>" ) != -1 );
88 assertTrue( actual.indexOf( "<a href=\"index.html\"></a>" ) != -1 );
89 }
90
91
92 protected String getTitleBlock( String title )
93 {
94 return "<title>" + title + "</title>";
95 }
96
97
98 protected String getAuthorBlock( String author )
99 {
100 return author;
101 }
102
103
104 protected String getDateBlock( String date )
105 {
106 return date;
107 }
108
109
110 protected String getHeadBlock()
111 {
112 return "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" +
113 "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title></title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/></head>";
114 }
115
116
117 protected String getBodyBlock()
118 {
119 return "<body></body></html>";
120 }
121
122
123 protected String getSectionTitleBlock( String title )
124 {
125 return title;
126 }
127
128
129 protected String getSection1Block( String title )
130 {
131 return "<div class=\"section\"><h2>" + title + "</h2></div>";
132 }
133
134
135 protected String getSection2Block( String title )
136 {
137 return "<div class=\"section\"><h3>" + title + "</h3></div>";
138 }
139
140
141 protected String getSection3Block( String title )
142 {
143 return "<div class=\"section\"><h4>" + title + "</h4></div>";
144 }
145
146
147 protected String getSection4Block( String title )
148 {
149 return "<div class=\"section\"><h5>" + title + "</h5></div>";
150 }
151
152
153 protected String getSection5Block( String title )
154 {
155 return "<div class=\"section\"><h6>" + title + "</h6></div>";
156 }
157
158
159 protected String getListBlock( String item )
160 {
161 return "<ul><li>" + item + "</li></ul>";
162 }
163
164
165 protected String getNumberedListBlock( String item )
166 {
167 return "<ol style=\"list-style-type: lower-roman\"><li>" + item + "</li></ol>";
168 }
169
170
171 protected String getDefinitionListBlock( String definum, String definition )
172 {
173 return "<dl><dt>" + definum + "</dt><dd>" + definition + "</dd></dl>";
174 }
175
176
177 protected String getFigureBlock( String source, String caption )
178 {
179 return "<img src=\"" + source + "\" alt=\"" + caption + "\" />";
180 }
181
182
183 protected String getTableBlock( String cell, String caption )
184 {
185 return "<table border=\"0\" class=\"bodyTable\">"
186 + "<caption>Table caption</caption><tr class=\"a\"><td>cell</td></tr>"
187 + "</table>";
188 }
189
190
191
192
193 public void testTable()
194 {
195 assertEquals( "Dummy!", "", "" );
196 }
197
198
199 protected String getParagraphBlock( String text )
200 {
201 return "<p>" + text + "</p>";
202 }
203
204
205 protected String getVerbatimBlock( String text )
206 {
207 return "<div class=\"source\"><pre>" + text + "</pre></div>";
208 }
209
210
211 protected String getHorizontalRuleBlock()
212 {
213 return "<hr />";
214 }
215
216
217 protected String getPageBreakBlock()
218 {
219 return "<!-- PB -->";
220 }
221
222
223 protected String getAnchorBlock( String anchor )
224 {
225 return "<a name=\"" + anchor + "\">" + anchor + "</a>";
226 }
227
228
229 protected String getLinkBlock( String link, String text )
230 {
231 return "<a href=\"" + link + "\">" + text + "</a>";
232 }
233
234
235 protected String getItalicBlock( String text )
236 {
237 return "<i>" + text + "</i>";
238 }
239
240
241 protected String getBoldBlock( String text )
242 {
243 return "<b>" + text + "</b>";
244 }
245
246
247 protected String getMonospacedBlock( String text )
248 {
249 return "<tt>" + text + "</tt>";
250 }
251
252
253 protected String getLineBreakBlock()
254 {
255 return "<br />";
256 }
257
258
259 protected String getNonBreakingSpaceBlock()
260 {
261 return " ";
262 }
263
264
265 protected String getTextBlock( String text )
266 {
267
268 return "~,_=,_-,_+,_*,_[,_],_<,_>,_{,_},_\\";
269 }
270
271
272 protected String getRawTextBlock( String text )
273 {
274 return text;
275 }
276
277
278
279
280 public void testEntities()
281 {
282 XhtmlSink sink = null;
283 Writer writer = new StringWriter();
284
285 try
286 {
287 sink = new XhtmlSink( writer );
288 sink.section( Sink.SECTION_LEVEL_1, null );
289 sink.sectionTitle( Sink.SECTION_LEVEL_1, null );
290 sink.text( "&", null );
291 sink.sectionTitle_( Sink.SECTION_LEVEL_1 );
292 sink.paragraph( null );
293 sink.text( "&", null );
294 sink.paragraph_();
295 sink.section_( Sink.SECTION_LEVEL_1 );
296 }
297 finally
298 {
299 sink.close();
300 }
301
302 assertEquals( "<div class=\"section\"><h2>&</h2><p>&</p></div>", writer.toString() );
303 }
304
305
306
307
308 public void testHead()
309 {
310 XhtmlSink sink = null;
311 Writer writer = new StringWriter();
312
313 try
314 {
315 sink = new XhtmlSink( writer );
316 sink.head();
317 sink.title();
318 sink.text( "Title" );
319 sink.title_();
320 sink.comment( "A comment" );
321 sink.author();
322
323 sink.text( "ģ&" );
324 sink.author_();
325 sink.head_();
326 }
327 finally
328 {
329 sink.close();
330 }
331
332 String exp =
333 "<head><title>Title</title><!-- A comment --><meta name=\"author\" content=\"ģ&\" /></head>";
334 assertTrue( writer.toString().indexOf( exp ) != -1 );
335 }
336
337
338 protected String getCommentBlock( String text )
339 {
340 return "<!-- Simple comment with - - - - -->";
341 }
342 }