1 package org.apache.maven.doxia.module.docbook;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.Writer;
23 import java.util.Locale;
24
25 import javax.swing.text.MutableAttributeSet;
26 import javax.swing.text.SimpleAttributeSet;
27
28 import org.apache.maven.doxia.sink.Sink;
29 import org.apache.maven.doxia.sink.impl.AbstractSinkTest;
30 import org.apache.maven.doxia.sink.impl.SinkUtils;
31 import org.apache.maven.doxia.util.DoxiaUtils;
32 import org.codehaus.plexus.util.FileUtils;
33
34 import static org.apache.maven.doxia.util.HtmlTools.escapeHTML;
35
36
37
38
39 public class DocBookSinkTest extends AbstractSinkTest
40 {
41
42 protected String outputExtension()
43 {
44 return "docbook";
45 }
46
47
48 protected Sink createSink( Writer writer )
49 {
50 return new DocBookSink( writer, "UTF-8" );
51 }
52
53
54 protected boolean isXmlSink()
55 {
56 return true;
57 }
58
59
60 protected String getTitleBlock( String title )
61 {
62 return "<articleinfo><title>" + title + "</title>";
63 }
64
65
66 protected String getAuthorBlock( String author )
67 {
68 return "<corpauthor>" + author + "</corpauthor>";
69 }
70
71
72 protected String getDateBlock( String date )
73 {
74 return "<date>" + date + "</date>";
75 }
76
77
78 protected String getHeadBlock()
79 {
80 return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE article PUBLIC \""
81 + SimplifiedDocbookMarkup.DEFAULT_XML_PUBLIC_ID + "\" "
82 + "\"" + SimplifiedDocbookMarkup.DEFAULT_XML_SYSTEM_ID + "\"><article>";
83 }
84
85
86 protected String getBodyBlock()
87 {
88 return "</article>";
89 }
90
91
92 protected String getArticleBlock()
93 {
94 return "";
95 }
96
97
98 protected String getNavigationBlock()
99 {
100 return "";
101 }
102
103
104 protected String getSidebarBlock()
105 {
106 return "<sidebar></sidebar>";
107 }
108
109
110 protected String getSectionTitleBlock( String title )
111 {
112 return "<title>" + title + "</title>";
113 }
114
115
116 protected String getSection1Block( String title )
117 {
118 return "<section><sectioninfo><title>" + title + "</title></sectioninfo></section>";
119 }
120
121
122 protected String getSection2Block( String title )
123 {
124 return "<section><sectioninfo><title>" + title + "</title></sectioninfo></section>";
125 }
126
127
128 protected String getSection3Block( String title )
129 {
130 return "<section><sectioninfo><title>" + title + "</title></sectioninfo></section>";
131 }
132
133
134 protected String getSection4Block( String title )
135 {
136 return "<section><sectioninfo><title>" + title + "</title></sectioninfo></section>";
137 }
138
139
140 protected String getSection5Block( String title )
141 {
142 return "<section><sectioninfo><title>" + title + "</title></sectioninfo></section>";
143 }
144
145
146 protected String getHeaderBlock()
147 {
148 return "<sectioninfo></sectioninfo>";
149 }
150
151
152 protected String getContentBlock()
153 {
154 return "";
155 }
156
157
158 protected String getFooterBlock()
159 {
160 return "";
161 }
162
163
164 protected String getListBlock( String item )
165 {
166 return "<itemizedlist><listitem><para>" + item + "</para></listitem>" + "</itemizedlist>";
167 }
168
169
170 protected String getNumberedListBlock( String item )
171 {
172 return "<orderedlist numeration=\"lowerroman\"><listitem><para>"
173 + item + "</para></listitem>" + "</orderedlist>";
174 }
175
176
177 protected String getDefinitionListBlock( String definum, String definition )
178 {
179 return "<variablelist><varlistentry><term>" + definum
180 + "</term>" + "<listitem><para>" + definition
181 + "</para></listitem>" + "</varlistentry>" + "</variablelist>";
182 }
183
184
185 protected String getFigureBlock( String source, String caption )
186 {
187 String format = FileUtils.extension( source ).toUpperCase( Locale.ENGLISH );
188 String figureBlock = "<mediaobject><imageobject>"
189 + "<imagedata fileref=\"" + escapeHTML( source ) + "\" format=\"" + escapeHTML( format ) + "\" />"
190 + "</imageobject>";
191 if ( caption != null )
192 {
193 figureBlock += "<caption><para>" + caption + "</para></caption>";
194 }
195 figureBlock += "</mediaobject>";
196
197 return figureBlock;
198 }
199
200
201 protected String getTableBlock( String cell, String caption )
202 {
203
204 MutableAttributeSet att = new SimpleAttributeSet();
205 att.addAttribute( "frame", "none" );
206 att.addAttribute( "rowsep", "0" );
207 att.addAttribute( "colsep", "0" );
208
209 return "<table" + SinkUtils.getAttributeString( att ) + "><title>" + caption
210 + "</title>" + "<tgroup cols=\"1\"><colspec align=\"center\" />" + "<tbody><row><entry>"
211 + cell + "</entry>" + "</row>" + "</tbody></tgroup>" + "</table>";
212 }
213
214
215 protected String getParagraphBlock( String text )
216 {
217 return "<para>" + text + "</para>";
218 }
219
220
221 protected String getDataBlock( String value, String text )
222 {
223 return text;
224 }
225
226
227 protected String getTimeBlock( String datetime, String text )
228 {
229 return text;
230 }
231
232
233 protected String getAddressBlock( String text )
234 {
235 return text;
236 }
237
238
239 protected String getBlockquoteBlock( String text )
240 {
241 return text;
242 }
243
244
245 protected String getDivisionBlock( String text )
246 {
247 return text;
248 }
249
250
251 protected String getVerbatimBlock( String text )
252 {
253 return "<programlisting>" + text + "</programlisting>";
254 }
255
256
257 protected String getHorizontalRuleBlock()
258 {
259 return "<!-- HR -->";
260 }
261
262
263 protected String getPageBreakBlock()
264 {
265 return "<!-- PB -->";
266 }
267
268
269 protected String getAnchorBlock( String anchor )
270 {
271 return "<anchor id=\"" + anchor + "\" />" + anchor + "<!-- anchor_end -->";
272 }
273
274
275 protected String getLinkBlock( String link, String text )
276 {
277 String linkend = DoxiaUtils.isInternalLink( link ) ? link.substring( 1 ) : link;
278 return "<link linkend=\"" + linkend + "\">" + text + "</link>";
279 }
280
281
282 protected String getInlineBlock( String text )
283 {
284 return text;
285 }
286
287
288 protected String getInlineItalicBlock( String text )
289 {
290 return "<emphasis>" + text + "</emphasis>";
291 }
292
293
294 protected String getInlineBoldBlock( String text )
295 {
296 return "<emphasis role=\"bold\">" + text + "</emphasis>";
297 }
298
299
300 protected String getInlineCodeBlock( String text )
301 {
302 return "<literal>" + text + "</literal>";
303 }
304
305
306 protected String getItalicBlock( String text )
307 {
308 return "<emphasis>" + text + "</emphasis>";
309 }
310
311
312 protected String getBoldBlock( String text )
313 {
314 return "<emphasis role=\"bold\">" + text + "</emphasis>";
315 }
316
317
318 protected String getMonospacedBlock( String text )
319 {
320 return "<literal>" + text + "</literal>";
321 }
322
323
324 protected String getLineBreakBlock()
325 {
326 return "<!-- LB -->";
327 }
328
329
330 protected String getLineBreakOpportunityBlock()
331 {
332 return "";
333 }
334
335
336 protected String getNonBreakingSpaceBlock()
337 {
338 return " ";
339 }
340
341
342 protected String getTextBlock( String text )
343 {
344
345 return "~,_=,_-,_+,_*,_[,_],_<,_>,_{,_},_\\";
346 }
347
348
349 protected String getRawTextBlock( String text )
350 {
351
352 return "";
353 }
354
355
356 protected String getCommentBlock( String text )
357 {
358 return "<!--" + toXmlComment( text ) + "-->";
359 }
360 }