View Javadoc

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