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
24 import java.util.Locale;
25
26 import javax.swing.text.MutableAttributeSet;
27 import javax.swing.text.SimpleAttributeSet;
28
29 import org.apache.maven.doxia.sink.AbstractSinkTest;
30 import org.apache.maven.doxia.sink.Sink;
31 import org.apache.maven.doxia.sink.SinkUtils;
32 import org.apache.maven.doxia.util.DoxiaUtils;
33
34 import org.codehaus.plexus.util.FileUtils;
35
36
37
38
39
40 public class DocBookSinkTest extends AbstractSinkTest
41 {
42
43 protected String outputExtension()
44 {
45 return "docbook";
46 }
47
48
49 protected Sink createSink( Writer writer )
50 {
51 return new DocBookSink( writer, "UTF-8" );
52 }
53
54
55 protected boolean isXmlSink()
56 {
57 return true;
58 }
59
60
61 protected String getTitleBlock( String title )
62 {
63 return "<articleinfo><title>" + title + "</title>";
64 }
65
66
67 protected String getAuthorBlock( String author )
68 {
69 return "<corpauthor>" + author + "</corpauthor>";
70 }
71
72
73 protected String getDateBlock( String date )
74 {
75 return "<date>" + date + "</date>";
76 }
77
78
79 protected String getHeadBlock()
80 {
81 return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE article PUBLIC \""
82 + SimplifiedDocbookMarkup.DEFAULT_XML_PUBLIC_ID + "\" "
83 + "\"" + SimplifiedDocbookMarkup.DEFAULT_XML_SYSTEM_ID + "\"><article>";
84 }
85
86
87 protected String getBodyBlock()
88 {
89 return "</article>";
90 }
91
92
93 protected String getSectionTitleBlock( String title )
94 {
95 return "<title>" + title + "</title>";
96 }
97
98
99 protected String getSection1Block( String title )
100 {
101 return "<section><title>" + title + "</title>" + "</section>";
102 }
103
104
105 protected String getSection2Block( String title )
106 {
107 return "<section><title>" + title + "</title>" + "</section>";
108 }
109
110
111 protected String getSection3Block( String title )
112 {
113 return "<section><title>" + title + "</title>" + "</section>";
114 }
115
116
117 protected String getSection4Block( String title )
118 {
119 return "<section><title>" + title + "</title>" + "</section>";
120 }
121
122
123 protected String getSection5Block( String title )
124 {
125 return "<section><title>" + title + "</title>" + "</section>";
126 }
127
128
129 protected String getListBlock( String item )
130 {
131 return "<itemizedlist><listitem><para>" + item + "</para></listitem>" + "</itemizedlist>";
132 }
133
134
135 protected String getNumberedListBlock( String item )
136 {
137 return "<orderedlist numeration=\"lowerroman\"><listitem><para>"
138 + item + "</para></listitem>" + "</orderedlist>";
139 }
140
141
142 protected String getDefinitionListBlock( String definum, String definition )
143 {
144 return "<variablelist><varlistentry><term>" + definum
145 + "</term>" + "<listitem><para>" + definition
146 + "</para></listitem>" + "</varlistentry>" + "</variablelist>";
147 }
148
149
150 protected String getFigureBlock( String source, String caption )
151 {
152 String format = FileUtils.extension( source ).toUpperCase( Locale.ENGLISH );
153 String figureBlock = "<mediaobject><imageobject>"
154 + "<imagedata fileref=\"" + source + "\" format=\"" + format + "\" />"
155 + "</imageobject>";
156 if ( caption != null )
157 {
158 figureBlock += "<caption><para>" + caption + "</para></caption>";
159 }
160 figureBlock += "</mediaobject>";
161
162 return figureBlock;
163 }
164
165
166 protected String getTableBlock( String cell, String caption )
167 {
168
169 MutableAttributeSet att = new SimpleAttributeSet();
170 att.addAttribute( "frame", "none" );
171 att.addAttribute( "rowsep", "0" );
172 att.addAttribute( "colsep", "0" );
173
174 return "<table" + SinkUtils.getAttributeString( att ) + "><title>" + caption
175 + "</title>" + "<tgroup cols=\"1\"><colspec align=\"center\" />" + "<tbody><row><entry>"
176 + cell + "</entry>" + "</row>" + "</tbody></tgroup>" + "</table>";
177 }
178
179
180 protected String getParagraphBlock( String text )
181 {
182 return "<para>" + text + "</para>";
183 }
184
185
186 protected String getVerbatimBlock( String text )
187 {
188 return "<programlisting>" + text + "</programlisting>";
189 }
190
191
192 protected String getHorizontalRuleBlock()
193 {
194 return "<!-- HR -->";
195 }
196
197
198 protected String getPageBreakBlock()
199 {
200 return "<!-- PB -->";
201 }
202
203
204 protected String getAnchorBlock( String anchor )
205 {
206 return "<anchor id=\"" + anchor + "\" />" + anchor + "<!-- anchor_end -->";
207 }
208
209
210 protected String getLinkBlock( String link, String text )
211 {
212 String linkend = DoxiaUtils.isInternalLink( link ) ? link.substring( 1 ) : link;
213 return "<link linkend=\"" + linkend + "\">" + text + "</link>";
214 }
215
216
217 protected String getItalicBlock( String text )
218 {
219 return "<emphasis>" + text + "</emphasis>";
220 }
221
222
223 protected String getBoldBlock( String text )
224 {
225 return "<emphasis role=\"bold\">" + text + "</emphasis>";
226 }
227
228
229 protected String getMonospacedBlock( String text )
230 {
231 return "<literal>" + text + "</literal>";
232 }
233
234
235 protected String getLineBreakBlock()
236 {
237 return "<!-- LB -->";
238 }
239
240
241 protected String getNonBreakingSpaceBlock()
242 {
243 return " ";
244 }
245
246
247 protected String getTextBlock( String text )
248 {
249
250 return "~,_=,_-,_+,_*,_[,_],_<,_>,_{,_},_\\";
251 }
252
253
254 protected String getRawTextBlock( String text )
255 {
256
257 return "";
258 }
259
260
261 protected String getCommentBlock( String text )
262 {
263 return "<!-- Simple comment with - - - - -->";
264 }
265 }