View Javadoc
1   package org.apache.maven.doxia.sink.impl;
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  import java.util.LinkedList;
23  import java.util.List;
24  
25  import org.apache.maven.doxia.sink.SinkEventAttributes;
26  import org.apache.maven.doxia.sink.impl.AbstractSink;
27  
28  /**
29   * This sink is used for testing purposes in order to check wether
30   * the input of some parser is well-formed.
31   *
32   * @author ltheussl
33   * @version $Id: SinkEventTestingSink.html 979316 2016-02-02 21:51:43Z hboutemy $
34   * @since 1.1
35   */
36  public class SinkEventTestingSink
37      extends AbstractSink
38  {
39      /** The list of sink events. */
40      private final List<SinkEventElement> events = new LinkedList<SinkEventElement>();
41  
42      /**
43       * Return the collected list of SinkEventElements.
44       *
45       * @return the collected list of SinkEventElements.
46       */
47      public List<SinkEventElement> getEventList()
48      {
49          return this.events;
50      }
51  
52      /** Clears the list of sink events. */
53      public void reset()
54      {
55          this.events.clear();
56      }
57  
58        //
59       // sink methods
60      //
61  
62      @Override
63      public void head()
64      {
65          addEvent( "head" );
66      }
67  
68      @Override
69      public void head_()
70      {
71          addEvent( "head_" );
72      }
73  
74      @Override
75      public void body()
76      {
77          addEvent( "body" );
78      }
79  
80      @Override
81      public void body_()
82      {
83          addEvent( "body_" );
84      }
85  
86      @Override
87      public void section1()
88      {
89          addEvent( "section1" );
90      }
91  
92      @Override
93      public void section1_()
94      {
95          addEvent( "section1_" );
96      }
97  
98      @Override
99      public void section2()
100     {
101         addEvent( "section2" );
102     }
103 
104     @Override
105     public void section2_()
106     {
107         addEvent( "section2_" );
108     }
109 
110     @Override
111     public void section3()
112     {
113         addEvent( "section3" );
114     }
115 
116     @Override
117     public void section3_()
118     {
119         addEvent( "section3_" );
120     }
121 
122     @Override
123     public void section4()
124     {
125         addEvent( "section4" );
126     }
127 
128     @Override
129     public void section4_()
130     {
131         addEvent( "section4_" );
132     }
133 
134     @Override
135     public void section5()
136     {
137         addEvent( "section5" );
138     }
139 
140     @Override
141     public void section5_()
142     {
143         addEvent( "section5_" );
144     }
145 
146     @Override
147     public void section6()
148     {
149         addEvent( "section6" );
150     }
151 
152     @Override
153     public void section6_()
154     {
155         addEvent( "section6_" );
156     }
157 
158     @Override
159     public void list()
160     {
161         addEvent( "list" );
162     }
163 
164     @Override
165     public void list_()
166     {
167         addEvent( "list_" );
168     }
169 
170     @Override
171     public void listItem()
172     {
173         addEvent( "listItem" );
174     }
175 
176     @Override
177     public void listItem_()
178     {
179         addEvent( "listItem_" );
180     }
181 
182     @Override
183     public void numberedList( int numbering )
184     {
185         addEvent( "numberedList", new Object[] {new Integer( numbering )} );
186     }
187 
188     @Override
189     public void numberedList_()
190     {
191         addEvent( "numberedList_" );
192     }
193 
194     @Override
195     public void numberedListItem()
196     {
197         addEvent( "numberedListItem" );
198     }
199 
200     @Override
201     public void numberedListItem_()
202     {
203         addEvent( "numberedListItem_" );
204     }
205 
206     @Override
207     public void definitionList()
208     {
209         addEvent( "definitionList" );
210     }
211 
212     @Override
213     public void definitionList_()
214     {
215         addEvent( "definitionList_" );
216     }
217 
218     @Override
219     public void definitionListItem()
220     {
221         addEvent( "definitionListItem" );
222     }
223 
224     @Override
225     public void definitionListItem_()
226     {
227         addEvent( "definitionListItem_" );
228     }
229 
230     @Override
231     public void definition()
232     {
233         addEvent( "definition" );
234     }
235 
236     @Override
237     public void definition_()
238     {
239         addEvent( "definition_" );
240     }
241 
242     @Override
243     public void figure()
244     {
245         addEvent( "figure" );
246     }
247 
248     @Override
249     public void figure_()
250     {
251         addEvent( "figure_" );
252     }
253 
254     @Override
255     public void table()
256     {
257         addEvent( "table" );
258     }
259 
260     @Override
261     public void table_()
262     {
263         addEvent( "table_" );
264     }
265 
266     @Override
267     public void tableRows( int[] justification, boolean grid )
268     {
269         addEvent( "tableRows", new Object[] {justification, new Boolean( grid )} );
270     }
271 
272     @Override
273     public void tableRows_()
274     {
275         addEvent( "tableRows_" );
276     }
277 
278     @Override
279     public void tableRow()
280     {
281         addEvent( "tableRow" );
282     }
283 
284     @Override
285     public void tableRow_()
286     {
287         addEvent( "tableRow_" );
288     }
289 
290     @Override
291     public void title()
292     {
293         addEvent( "title" );
294     }
295 
296     @Override
297     public void title_()
298     {
299         addEvent( "title_" );
300     }
301 
302     @Override
303     public void author()
304     {
305         addEvent( "author" );
306     }
307 
308     @Override
309     public void author_()
310     {
311         addEvent( "author_" );
312     }
313 
314     @Override
315     public void date()
316     {
317         addEvent( "date" );
318     }
319 
320     @Override
321     public void date_()
322     {
323         addEvent( "date_" );
324     }
325 
326     @Override
327     public void sectionTitle()
328     {
329         addEvent( "sectionTitle" );
330     }
331 
332     @Override
333     public void sectionTitle_()
334     {
335         addEvent( "sectionTitle_" );
336     }
337 
338     @Override
339     public void sectionTitle1()
340     {
341         addEvent( "sectionTitle1" );
342     }
343 
344     @Override
345     public void sectionTitle1_()
346     {
347         addEvent( "sectionTitle1_" );
348     }
349 
350     @Override
351     public void sectionTitle2()
352     {
353         addEvent( "sectionTitle2" );
354     }
355 
356     @Override
357     public void sectionTitle2_()
358     {
359         addEvent( "sectionTitle2_" );
360     }
361 
362     @Override
363     public void sectionTitle3()
364     {
365         addEvent( "sectionTitle3" );
366     }
367 
368     @Override
369     public void sectionTitle3_()
370     {
371         addEvent( "sectionTitle3_" );
372     }
373 
374     @Override
375     public void sectionTitle4()
376     {
377         addEvent( "sectionTitle4" );
378     }
379 
380     @Override
381     public void sectionTitle4_()
382     {
383         addEvent( "sectionTitle4_" );
384     }
385 
386     @Override
387     public void sectionTitle5()
388     {
389         addEvent( "sectionTitle5" );
390     }
391 
392     @Override
393     public void sectionTitle5_()
394     {
395         addEvent( "sectionTitle5_" );
396     }
397 
398     @Override
399     public void sectionTitle6()
400     {
401         addEvent( "sectionTitle6" );
402     }
403 
404     @Override
405     public void sectionTitle6_()
406     {
407         addEvent( "sectionTitle6_" );
408     }
409 
410     @Override
411     public void paragraph()
412     {
413         addEvent( "paragraph" );
414     }
415 
416     @Override
417     public void paragraph_()
418     {
419         addEvent( "paragraph_" );
420     }
421 
422     @Override
423     public void verbatim( boolean boxed )
424     {
425         addEvent( "verbatim", new Object[] {new Boolean( boxed )} );
426     }
427 
428     @Override
429     public void verbatim_()
430     {
431         addEvent( "verbatim_" );
432     }
433 
434     @Override
435     public void definedTerm()
436     {
437         addEvent( "definedTerm" );
438     }
439 
440     @Override
441     public void definedTerm_()
442     {
443         addEvent( "definedTerm_" );
444     }
445 
446     @Override
447     public void figureCaption()
448     {
449         addEvent( "figureCaption" );
450     }
451 
452     @Override
453     public void figureCaption_()
454     {
455         addEvent( "figureCaption_" );
456     }
457 
458     @Override
459     public void tableCell()
460     {
461         addEvent( "tableCell" );
462     }
463 
464     @Override
465     public void tableCell( String width )
466     {
467         addEvent( "tableCell", new Object[] {width} );
468     }
469 
470     @Override
471     public void tableCell_()
472     {
473         addEvent( "tableCell_" );
474     }
475 
476     @Override
477     public void tableHeaderCell()
478     {
479         addEvent( "tableHeaderCell" );
480     }
481 
482     @Override
483     public void tableHeaderCell( String width )
484     {
485         addEvent( "tableHeaderCell", new Object[] {width} );
486     }
487 
488     @Override
489     public void tableHeaderCell_()
490     {
491         addEvent( "tableHeaderCell_" );
492     }
493 
494     @Override
495     public void tableCaption()
496     {
497         addEvent( "tableCaption" );
498     }
499 
500     @Override
501     public void tableCaption_()
502     {
503         addEvent( "tableCaption_" );
504     }
505 
506     @Override
507     public void figureGraphics( String name )
508     {
509         addEvent( "figureGraphics", new Object[] {name} );
510     }
511 
512     @Override
513     public void horizontalRule()
514     {
515         addEvent( "horizontalRule" );
516     }
517 
518     @Override
519     public void pageBreak()
520     {
521         addEvent( "pageBreak" );
522     }
523 
524     @Override
525     public void anchor( String name )
526     {
527         addEvent( "anchor", new Object[] {name} );
528     }
529 
530     @Override
531     public void anchor_()
532     {
533         addEvent( "anchor_" );
534     }
535 
536     @Override
537     public void link( String name )
538     {
539         addEvent( "link", new Object[] {name} );
540     }
541 
542     @Override
543     public void link_()
544     {
545         addEvent( "link_" );
546     }
547 
548     @Override
549     public void italic()
550     {
551         addEvent( "italic" );
552     }
553 
554     @Override
555     public void italic_()
556     {
557         addEvent( "italic_" );
558     }
559 
560     @Override
561     public void bold()
562     {
563         addEvent( "bold" );
564     }
565 
566     @Override
567     public void bold_()
568     {
569         addEvent( "bold_" );
570     }
571 
572     @Override
573     public void monospaced()
574     {
575         addEvent( "monospaced" );
576     }
577 
578     @Override
579     public void monospaced_()
580     {
581         addEvent( "monospaced_" );
582     }
583 
584     @Override
585     public void lineBreak()
586     {
587         addEvent( "lineBreak" );
588     }
589 
590     @Override
591     public void nonBreakingSpace()
592     {
593         addEvent( "nonBreakingSpace" );
594     }
595 
596     @Override
597     public void text( String text )
598     {
599         addEvent( "text", new Object[] {text} );
600     }
601 
602     @Override
603     public void rawText( String text )
604     {
605         addEvent( "rawText", new Object[] {text} );
606     }
607 
608     @Override
609     public void comment( String comment )
610     {
611         addEvent( "comment", new Object[] {comment} );
612     }
613 
614     @Override
615     public void flush()
616     {
617         addEvent( "flush" );
618     }
619 
620     @Override
621     public void close()
622     {
623         addEvent( "close" );
624     }
625 
626     @Override
627     public void head( SinkEventAttributes attributes )
628     {
629         addEvent( "head", new Object[] {attributes} );
630     }
631 
632     @Override
633     public void title( SinkEventAttributes attributes )
634     {
635         addEvent( "title", new Object[] {attributes} );
636     }
637 
638     @Override
639     public void author( SinkEventAttributes attributes )
640     {
641         addEvent( "author", new Object[] {attributes} );
642     }
643 
644     @Override
645     public void date( SinkEventAttributes attributes )
646     {
647         addEvent( "date", new Object[] {attributes} );
648     }
649 
650     @Override
651     public void body( SinkEventAttributes attributes )
652     {
653         addEvent( "body", new Object[] {attributes} );
654     }
655 
656     @Override
657     public void section( int level, SinkEventAttributes attributes )
658     {
659         addEvent( "section" + level, new Object[] {attributes} );
660     }
661 
662     @Override
663     public void section_( int level )
664     {
665         addEvent( "section" + level + "_" );
666     }
667 
668     @Override
669     public void sectionTitle( int level, SinkEventAttributes attributes )
670     {
671         addEvent( "sectionTitle" + level, new Object[] {attributes} );
672     }
673 
674     @Override
675     public void sectionTitle_( int level )
676     {
677 
678         addEvent( "sectionTitle" + level + "_" );
679     }
680 
681     @Override
682     public void list( SinkEventAttributes attributes )
683     {
684         addEvent( "list", new Object[] {attributes} );
685     }
686 
687     @Override
688     public void listItem( SinkEventAttributes attributes )
689     {
690         addEvent( "listItem", new Object[] {attributes} );
691     }
692 
693     @Override
694     public void numberedList( int numbering, SinkEventAttributes attributes )
695     {
696         addEvent( "numberedList", new Object[] {new Integer( numbering ), attributes} );
697     }
698 
699     @Override
700     public void numberedListItem( SinkEventAttributes attributes )
701     {
702         addEvent( "numberedListItem", new Object[] {attributes} );
703     }
704 
705     @Override
706     public void definitionList( SinkEventAttributes attributes )
707     {
708         addEvent( "definitionList", new Object[] {attributes} );
709     }
710 
711     @Override
712     public void definitionListItem( SinkEventAttributes attributes )
713     {
714         addEvent( "definitionListItem", new Object[] {attributes} );
715     }
716 
717     @Override
718     public void definition( SinkEventAttributes attributes )
719     {
720         addEvent( "definition", new Object[] {attributes} );
721     }
722 
723     @Override
724     public void definedTerm( SinkEventAttributes attributes )
725     {
726         addEvent( "definedTerm", new Object[] {attributes} );
727     }
728 
729     @Override
730     public void figure( SinkEventAttributes attributes )
731     {
732         addEvent( "figure", new Object[] {attributes} );
733     }
734 
735     @Override
736     public void figureCaption( SinkEventAttributes attributes )
737     {
738         addEvent( "figureCaption", new Object[] {attributes} );
739     }
740 
741     @Override
742     public void figureGraphics( String src, SinkEventAttributes attributes )
743     {
744         addEvent( "figureGraphics", new Object[] {src, attributes} );
745     }
746 
747     @Override
748     public void table( SinkEventAttributes attributes )
749     {
750         addEvent( "table", new Object[] {attributes} );
751     }
752 
753     @Override
754     public void tableRow( SinkEventAttributes attributes )
755     {
756         addEvent( "tableRow", new Object[] {attributes} );
757     }
758 
759     @Override
760     public void tableCell( SinkEventAttributes attributes )
761     {
762         addEvent( "tableCell", new Object[] {attributes} );
763     }
764 
765     @Override
766     public void tableHeaderCell( SinkEventAttributes attributes )
767     {
768         addEvent( "tableHeaderCell", new Object[] {attributes} );
769     }
770 
771     @Override
772     public void tableCaption( SinkEventAttributes attributes )
773     {
774         addEvent( "tableCaption", new Object[] {attributes} );
775     }
776 
777     @Override
778     public void paragraph( SinkEventAttributes attributes )
779     {
780         addEvent( "paragraph", new Object[] {attributes} );
781     }
782 
783     @Override
784     public void verbatim( SinkEventAttributes attributes )
785     {
786         addEvent( "verbatim", new Object[] {attributes} );
787     }
788 
789     @Override
790     public void horizontalRule( SinkEventAttributes attributes )
791     {
792         addEvent( "horizontalRule", new Object[] {attributes} );
793     }
794 
795     @Override
796     public void anchor( String name, SinkEventAttributes attributes )
797     {
798         addEvent( "anchor", new Object[] {name, attributes} );
799     }
800 
801     @Override
802     public void link( String name, SinkEventAttributes attributes )
803     {
804         addEvent( "link", new Object[] {name, attributes} );
805     }
806 
807     @Override
808     public void lineBreak( SinkEventAttributes attributes )
809     {
810         addEvent( "lineBreak", new Object[] {attributes} );
811     }
812 
813     @Override
814     public void text( String text, SinkEventAttributes attributes )
815     {
816         addEvent( "text", new Object[] {text, attributes} );
817     }
818 
819     @Override
820     public void unknown( String name, Object[] requiredParams, SinkEventAttributes attributes )
821     {
822         addEvent( "unknown", new Object[] {name, requiredParams, attributes} );
823     }
824 
825       //
826      // private
827     //
828 
829     /**
830      * Adds a no-arg event to the list of events.
831      *
832      * @param string the name of the event.
833      */
834     private void addEvent( String string )
835     {
836         addEvent( string, null );
837     }
838 
839     /**
840      * Adds an event to the list of events.
841      *
842      * @param string the name of the event.
843      * @param arguments The array of arguments to the sink method.
844      */
845     private void addEvent( String string, Object[] arguments )
846     {
847         events.add( new SinkEventElement( string, arguments ) );
848     }
849 
850 }