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