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