View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.doxia.sink.impl;
20  
21  import org.apache.maven.doxia.sink.Sink;
22  
23  /**
24   * Static methods to generate standard Doxia sink events.
25   */
26  public class SinkTestDocument {
27  
28      /** Private constructor. */
29      private SinkTestDocument() {
30          // do not instantiate
31      }
32  
33      /**
34       * Dumps a full model that mimics aptconvert's test.apt,
35       * into the specified sink. The sink is flushed but not closed.
36       *
37       * @param sink The sink to receive the events.
38       */
39      public static void generate(Sink sink) {
40          generateHead(sink);
41  
42          sink.body();
43  
44          // TODO: what is this supposed to do?
45          // sink.sectionTitle();
46          // sink.text("Section Title");
47          // sink.sectionTitle_();
48  
49          sink.paragraph();
50          sink.text("Paragraph 1, line 1. Paragraph 1, line 2.");
51          sink.paragraph_();
52  
53          sink.paragraph();
54          sink.text("Paragraph 2, line 1. Paragraph 2, line 2.");
55          sink.paragraph_();
56  
57          sink.section1();
58          sink.sectionTitle1();
59          sink.text("Section title");
60          sink.sectionTitle1_();
61  
62          sink.section2();
63          sink.sectionTitle2();
64          sink.text("Sub-section title");
65          sink.sectionTitle2_();
66  
67          sink.section3();
68          sink.sectionTitle3();
69          sink.text("Sub-sub-section title");
70          sink.sectionTitle3_();
71  
72          sink.section4();
73          sink.sectionTitle4();
74          sink.text("Sub-sub-sub-section title");
75          sink.sectionTitle4_();
76  
77          sink.section5();
78          sink.sectionTitle5();
79          sink.text("Sub-sub-sub-sub-section title");
80          sink.sectionTitle5_();
81  
82          generateList(sink);
83  
84          sink.verbatim();
85          sink.inline(SinkEventAttributeSet.Semantics.CODE);
86          sink.text("Verbatim source text not contained in list item 3");
87          sink.inline_();
88          sink.verbatim_();
89  
90          generateNumberedList(sink);
91  
92          sink.paragraph();
93          sink.text("List numbering schemes: [[1]], [[a]], [[A]], [[i]], [[I]].");
94          sink.paragraph_();
95  
96          generateDefinitionList(sink);
97  
98          sink.paragraph();
99          sink.text("--- instead of +-- suppresses the box around verbatim text.");
100         sink.paragraph_();
101 
102         generateFigure(sink);
103 
104         generateTable(sink);
105 
106         sink.paragraph();
107         sink.text("No grid, no caption:");
108         sink.paragraph_();
109 
110         generateNoGridTable(sink);
111 
112         generateHeaderTable(sink);
113 
114         generateHorizontalRule(sink);
115 
116         generatePageBreak(sink);
117 
118         generateFonts(sink);
119 
120         generateAnchors(sink);
121 
122         generateLineBreak(sink);
123 
124         generateNonBreakingSpace(sink);
125 
126         generateSpecialCharacters(sink);
127 
128         sink.comment("A comment!");
129 
130         sink.section5_();
131         sink.section4_();
132         sink.section3_();
133         sink.section2_();
134         sink.section1_();
135 
136         sink.body_();
137 
138         sink.flush();
139     }
140 
141     /**
142      * Dumps a header with title, author and date elements
143      * into the specified sink. The sink is not flushed or closed.
144      *
145      * @param sink The sink to receive the events.
146      */
147     public static void generateHead(Sink sink) {
148         sink.head();
149 
150         sink.title();
151         sink.text("Title");
152         sink.title_();
153 
154         sink.author();
155         sink.text("Author");
156         sink.author_();
157 
158         sink.date();
159         sink.text("Date");
160         sink.date_();
161 
162         sink.head_();
163     }
164 
165     /**
166      * Dumps a list into the specified sink. The sink is not flushed or closed.
167      *
168      * @param sink The sink to receive the events.
169      */
170     public static void generateList(Sink sink) {
171         sink.list();
172 
173         sink.listItem();
174         sink.text("List item 1.");
175         sink.listItem_();
176 
177         sink.listItem();
178         sink.text("List item 2.");
179         sink.paragraph();
180         sink.text("Paragraph contained in list item 2.");
181         sink.paragraph_();
182 
183         sink.list();
184 
185         sink.listItem();
186         sink.text("Sub-list item 1.");
187         sink.listItem_();
188 
189         sink.listItem();
190         sink.text("Sub-list item 2.");
191         sink.listItem_();
192 
193         sink.list_();
194 
195         sink.listItem_();
196 
197         sink.listItem();
198         sink.text("List item 3. Force end of list:");
199         sink.listItem_();
200 
201         sink.list_();
202     }
203 
204     /**
205      * Dumps a numbered list into the specified sink.
206      * The sink is not flushed or closed.
207      *
208      * @param sink The sink to receive the events.
209      */
210     public static void generateNumberedList(Sink sink) {
211         sink.numberedList(Sink.NUMBERING_DECIMAL);
212 
213         sink.numberedListItem();
214         sink.text("Numbered item 1.");
215 
216         sink.numberedList(Sink.NUMBERING_UPPER_ALPHA);
217 
218         sink.numberedListItem();
219         sink.text("Numbered item A.");
220         sink.numberedListItem_();
221 
222         sink.numberedListItem();
223         sink.text("Numbered item B.");
224         sink.numberedListItem_();
225 
226         sink.numberedList_();
227 
228         sink.numberedListItem_();
229 
230         sink.numberedListItem();
231         sink.text("Numbered item 2.");
232         sink.numberedListItem_();
233 
234         sink.numberedList_();
235     }
236 
237     /**
238      * Dumps a definition list into the specified sink.
239      * The sink is not flushed or closed.
240      *
241      * @param sink The sink to receive the events.
242      */
243     public static void generateDefinitionList(Sink sink) {
244         String eol = System.getProperty("line.separator");
245 
246         sink.definitionList();
247 
248         sink.definitionListItem();
249         sink.definedTerm();
250         sink.text("Defined term 1");
251         sink.definedTerm_();
252         sink.definition();
253         sink.text("of definition list.");
254         sink.definition_();
255         sink.definitionListItem_();
256 
257         sink.definitionListItem();
258         sink.definedTerm();
259         sink.text("Defined term 2");
260         sink.definedTerm_();
261         sink.definition();
262         sink.text("of definition list.");
263         sink.verbatim();
264         sink.inline(SinkEventAttributeSet.Semantics.CODE);
265         sink.text("Verbatim source text" + eol + "                        in a box        ");
266         sink.inline_();
267         sink.verbatim_();
268         sink.definition_();
269         sink.definitionListItem_();
270 
271         sink.definitionList_();
272     }
273 
274     /**
275      * Dumps a figure with figure caption into the specified sink.
276      * The sink is not flushed or closed.
277      *
278      * @param sink The sink to receive the events.
279      */
280     public static void generateFigure(Sink sink) {
281         sink.figure(null);
282 
283         sink.figureGraphics("figure.png", null);
284 
285         sink.figureCaption(null);
286         sink.text("Figure caption", null);
287         sink.figureCaption_();
288 
289         sink.figure_();
290     }
291 
292     /**
293      * Dumps a table with grid and caption into the specified sink.
294      * The sink is not flushed or closed.
295      *
296      * @param sink The sink to receive the events.
297      */
298     public static void generateTable(Sink sink) {
299         int[] justify = {Sink.JUSTIFY_CENTER, Sink.JUSTIFY_LEFT, Sink.JUSTIFY_RIGHT};
300 
301         sink.table();
302 
303         sink.tableRows(justify, true);
304 
305         sink.tableRow();
306         sink.tableCell();
307         sink.text("Centered");
308         sink.lineBreak();
309         sink.text("cell 1,1");
310         sink.tableCell_();
311         sink.tableCell();
312         sink.text("Left-aligned");
313         sink.lineBreak();
314         sink.text("cell 1,2");
315         sink.tableCell_();
316         sink.tableCell();
317         sink.text("Right-aligned");
318         sink.lineBreak();
319         sink.text("cell 1,3");
320         sink.tableCell_();
321         sink.tableRow_();
322 
323         sink.tableRow();
324         sink.tableCell();
325         sink.text("cell 2,1");
326         sink.tableCell_();
327         sink.tableCell();
328         sink.text("cell 2,2");
329         sink.tableCell_();
330         sink.tableCell();
331         sink.text("cell 2,3");
332         sink.tableCell_();
333         sink.tableRow_();
334 
335         sink.tableRows_();
336 
337         sink.tableCaption();
338         sink.text("Table caption");
339         sink.tableCaption_();
340 
341         sink.table_();
342     }
343 
344     /**
345      * Dumps a table without grid into the specified sink.
346      * The sink is not flushed or closed.
347      *
348      * @param sink The sink to receive the events.
349      */
350     public static void generateNoGridTable(Sink sink) {
351         int[] justify = {Sink.JUSTIFY_CENTER, Sink.JUSTIFY_CENTER};
352 
353         sink.table();
354 
355         sink.tableRows(justify, false);
356 
357         sink.tableRow();
358         sink.tableCell();
359         sink.text("cell");
360         sink.tableCell_();
361         sink.tableCell();
362         sink.text("cell");
363         sink.tableCell_();
364         sink.tableRow_();
365 
366         sink.tableRow();
367         sink.tableCell();
368         sink.text("cell");
369         sink.tableCell_();
370         sink.tableCell();
371         sink.text("cell");
372         sink.tableCell_();
373         sink.tableRow_();
374 
375         sink.tableRows_();
376 
377         sink.table_();
378     }
379 
380     /**
381      * Dumps a table with a header row into the specified sink.
382      * The sink is not flushed or closed.
383      *
384      * @param sink The sink to receive the events.
385      */
386     public static void generateHeaderTable(Sink sink) {
387         int[] justify = {Sink.JUSTIFY_CENTER, Sink.JUSTIFY_CENTER};
388 
389         sink.table();
390 
391         sink.tableRows(justify, true);
392 
393         sink.tableRow();
394         sink.tableHeaderCell();
395         sink.text("header");
396         sink.tableHeaderCell_();
397         sink.tableHeaderCell();
398         sink.text("header");
399         sink.tableHeaderCell_();
400         sink.tableRow_();
401 
402         sink.tableRow();
403         sink.tableCell();
404         sink.text("cell");
405         sink.tableCell_();
406         sink.tableCell();
407         sink.text("cell");
408         sink.tableCell_();
409         sink.tableRow_();
410 
411         sink.tableRows_();
412 
413         sink.table_();
414     }
415 
416     /**
417      * Dumps a paragraph with italic, bold and monospaced text
418      * into the specified sink. The sink is not flushed or closed.
419      *
420      * @param sink The sink to receive the events.
421      */
422     public static void generateFonts(Sink sink) {
423         sink.paragraph();
424 
425         sink.inline(SinkEventAttributeSet.Semantics.ITALIC);
426         sink.text("Italic");
427         sink.inline_();
428         sink.text(" font. ");
429 
430         sink.inline(SinkEventAttributeSet.Semantics.BOLD);
431         sink.text("Bold");
432         sink.inline_();
433         sink.text(" font. ");
434 
435         sink.inline(SinkEventAttributeSet.Semantics.CODE);
436         sink.text("Monospaced (code)");
437         sink.inline_();
438         sink.text(" font.");
439 
440         sink.paragraph_();
441     }
442 
443     /**
444      * Dumps a paragraph with anchor and link elements
445      * into the specified sink. The sink is not flushed or closed.
446      *
447      * @param sink The sink to receive the events.
448      */
449     public static void generateAnchors(Sink sink) {
450         sink.paragraph();
451 
452         sink.anchor("Anchor");
453         sink.text("Anchor");
454         sink.anchor_();
455 
456         sink.text(". Link to ");
457         sink.link("#Anchor");
458         sink.text("Anchor");
459         sink.link_();
460 
461         sink.text(". Link to ");
462         sink.link("http://www.pixware.fr");
463         sink.text("http://www.pixware.fr");
464         sink.link_();
465 
466         sink.text(". Link to ");
467         sink.link("#Anchor");
468         sink.text("showing alternate text");
469         sink.link_();
470 
471         sink.text(". Link to ");
472         sink.link("http://www.pixware.fr");
473         sink.text("Pixware home page");
474         sink.link_();
475 
476         sink.text(".");
477 
478         sink.paragraph_();
479     }
480 
481     /**
482      * Dumps a horizontal rule block into the specified sink.
483      * The sink is not flushed or closed.
484      *
485      * @param sink The sink to receive the events.
486      */
487     public static void generateHorizontalRule(Sink sink) {
488         sink.paragraph();
489         sink.text("Horizontal line:");
490         sink.paragraph_();
491         sink.horizontalRule();
492     }
493 
494     /**
495      * Dumps a pageBreak block into the specified sink.
496      * The sink is not flushed or closed.
497      *
498      * @param sink The sink to receive the events.
499      */
500     public static void generatePageBreak(Sink sink) {
501         sink.pageBreak();
502         sink.paragraph();
503         sink.text("New page.");
504         sink.paragraph_();
505     }
506 
507     /**
508      * Dumps a lineBreak block into the specified sink.
509      * The sink is not flushed or closed.
510      *
511      * @param sink The sink to receive the events.
512      */
513     public static void generateLineBreak(Sink sink) {
514         sink.paragraph();
515         sink.text("Force line");
516         sink.lineBreak();
517         sink.text("break.");
518         sink.paragraph_();
519     }
520 
521     /**
522      * Dumps a nonBreakingSpace block into the specified sink.
523      * The sink is not flushed or closed.
524      *
525      * @param sink The sink to receive the events.
526      */
527     public static void generateNonBreakingSpace(Sink sink) {
528         sink.paragraph();
529         sink.text("Non");
530         sink.nonBreakingSpace();
531         sink.text("breaking");
532         sink.nonBreakingSpace();
533         sink.text("space.");
534         sink.paragraph_();
535     }
536 
537     /**
538      * Dumps a special character block into the specified sink.
539      * The sink is not flushed or closed.
540      *
541      * @param sink The sink to receive the events.
542      */
543     public static void generateSpecialCharacters(Sink sink) {
544         sink.paragraph();
545         sink.text("Escaped special characters:");
546         sink.lineBreak();
547         sink.text("~");
548         sink.lineBreak();
549         sink.text("=");
550         sink.lineBreak();
551         sink.text("-");
552         sink.lineBreak();
553         sink.text("+");
554         sink.lineBreak();
555         sink.text("*");
556         sink.lineBreak();
557         sink.text("[");
558         sink.lineBreak();
559         sink.text("]");
560         sink.lineBreak();
561         sink.text("<");
562         sink.lineBreak();
563         sink.text(">");
564         sink.lineBreak();
565         sink.text("{");
566         sink.lineBreak();
567         sink.text("}");
568         sink.lineBreak();
569         sink.text("\\");
570         sink.paragraph_();
571 
572         sink.paragraph();
573         sink.text("Copyright symbol:");
574         sink.lineBreak();
575         sink.text("\u00a9");
576         sink.paragraph_();
577     }
578 }