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