View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.doxia.sink.impl;
20  
21  import java.util.LinkedList;
22  import java.util.List;
23  
24  import org.apache.maven.doxia.sink.SinkEventAttributes;
25  
26  /**
27   * This sink is used for testing purposes in order to check wether
28   * the input of some parser is well-formed.
29   *
30   * @author ltheussl
31   * @since 1.1
32   */
33  public class SinkEventTestingSink extends AbstractSink {
34      /** The list of sink events. */
35      private final List<SinkEventElement> events = new LinkedList<>();
36  
37      /**
38       * Return the collected list of SinkEventElements.
39       *
40       * @return the collected list of SinkEventElements.
41       */
42      public List<SinkEventElement> getEventList() {
43          return this.events;
44      }
45  
46      /** Clears the list of sink events. */
47      public void reset() {
48          this.events.clear();
49      }
50  
51      //
52      // sink methods
53      //
54  
55      @Override
56      public void head_() {
57          addEvent("head_");
58      }
59  
60      @Override
61      public void body_() {
62          addEvent("body_");
63      }
64  
65      @Override
66      public void article_() {
67          addEvent("article_");
68      }
69  
70      @Override
71      public void navigation_() {
72          addEvent("navigation_");
73      }
74  
75      @Override
76      public void sidebar_() {
77          addEvent("sidebar_");
78      }
79  
80      @Override
81      public void list_() {
82          addEvent("list_");
83      }
84  
85      @Override
86      public void listItem_() {
87          addEvent("listItem_");
88      }
89  
90      @Override
91      public void numberedList_() {
92          addEvent("numberedList_");
93      }
94  
95      @Override
96      public void numberedListItem_() {
97          addEvent("numberedListItem_");
98      }
99  
100     @Override
101     public void definitionList_() {
102         addEvent("definitionList_");
103     }
104 
105     @Override
106     public void definitionListItem_() {
107         addEvent("definitionListItem_");
108     }
109 
110     @Override
111     public void definition_() {
112         addEvent("definition_");
113     }
114 
115     @Override
116     public void figure_() {
117         addEvent("figure_");
118     }
119 
120     @Override
121     public void table_() {
122         addEvent("table_");
123     }
124 
125     @Override
126     public void tableRows(int[] justification, boolean grid) {
127         addEvent("tableRows", new Object[] {justification, grid});
128     }
129 
130     @Override
131     public void tableRows_() {
132         addEvent("tableRows_");
133     }
134 
135     @Override
136     public void tableRow_() {
137         addEvent("tableRow_");
138     }
139 
140     @Override
141     public void title_() {
142         addEvent("title_");
143     }
144 
145     @Override
146     public void author_() {
147         addEvent("author_");
148     }
149 
150     @Override
151     public void date_() {
152         addEvent("date_");
153     }
154 
155     @Override
156     public void header_() {
157         addEvent("header_");
158     }
159 
160     @Override
161     public void content_() {
162         addEvent("content_");
163     }
164 
165     @Override
166     public void footer_() {
167         addEvent("footer_");
168     }
169 
170     @Override
171     public void paragraph_() {
172         addEvent("paragraph_");
173     }
174 
175     @Override
176     public void data_() {
177         addEvent("data_");
178     }
179 
180     @Override
181     public void time_() {
182         addEvent("time_");
183     }
184 
185     @Override
186     public void address_() {
187         addEvent("address_");
188     }
189 
190     @Override
191     public void blockquote_() {
192         addEvent("blockquote_");
193     }
194 
195     @Override
196     public void division_() {
197         addEvent("division_");
198     }
199 
200     @Override
201     public void verbatim_() {
202         addEvent("verbatim_");
203     }
204 
205     @Override
206     public void definedTerm_() {
207         addEvent("definedTerm_");
208     }
209 
210     @Override
211     public void figureCaption_() {
212         addEvent("figureCaption_");
213     }
214 
215     @Override
216     public void tableCell_() {
217         addEvent("tableCell_");
218     }
219 
220     @Override
221     public void tableHeaderCell_() {
222         addEvent("tableHeaderCell_");
223     }
224 
225     @Override
226     public void tableCaption_() {
227         addEvent("tableCaption_");
228     }
229 
230     @Override
231     public void pageBreak() {
232         addEvent("pageBreak");
233     }
234 
235     @Override
236     public void anchor_() {
237         addEvent("anchor_");
238     }
239 
240     @Override
241     public void link_() {
242         addEvent("link_");
243     }
244 
245     @Override
246     public void inline_() {
247         addEvent("inline_");
248     }
249 
250     @Override
251     public void italic() {
252         addEvent("italic");
253     }
254 
255     @Override
256     public void italic_() {
257         addEvent("italic_");
258     }
259 
260     @Override
261     public void bold() {
262         addEvent("bold");
263     }
264 
265     @Override
266     public void bold_() {
267         addEvent("bold_");
268     }
269 
270     @Override
271     public void monospaced() {
272         addEvent("monospaced");
273     }
274 
275     @Override
276     public void monospaced_() {
277         addEvent("monospaced_");
278     }
279 
280     @Override
281     public void nonBreakingSpace() {
282         addEvent("nonBreakingSpace");
283     }
284 
285     @Override
286     public void rawText(String text) {
287         addEvent("rawText", new Object[] {text});
288     }
289 
290     @Override
291     public void comment(String comment) {
292         addEvent("comment", new Object[] {comment});
293     }
294 
295     @Override
296     public void flush() {
297         addEvent("flush");
298     }
299 
300     @Override
301     public void close() {
302         addEvent("close");
303     }
304 
305     @Override
306     public void head(SinkEventAttributes attributes) {
307         addEvent("head", new Object[] {attributes});
308     }
309 
310     @Override
311     public void title(SinkEventAttributes attributes) {
312         addEvent("title", new Object[] {attributes});
313     }
314 
315     @Override
316     public void author(SinkEventAttributes attributes) {
317         addEvent("author", new Object[] {attributes});
318     }
319 
320     @Override
321     public void date(SinkEventAttributes attributes) {
322         addEvent("date", new Object[] {attributes});
323     }
324 
325     @Override
326     public void body(SinkEventAttributes attributes) {
327         addEvent("body", new Object[] {attributes});
328     }
329 
330     @Override
331     public void article(SinkEventAttributes attributes) {
332         addEvent("article", new Object[] {attributes});
333     }
334 
335     @Override
336     public void navigation(SinkEventAttributes attributes) {
337         addEvent("navigation", new Object[] {attributes});
338     }
339 
340     @Override
341     public void sidebar(SinkEventAttributes attributes) {
342         addEvent("sidebar", new Object[] {attributes});
343     }
344 
345     @Override
346     public void section(int level, SinkEventAttributes attributes) {
347         addEvent("section" + level, new Object[] {attributes});
348     }
349 
350     @Override
351     public void section_(int level) {
352         addEvent("section" + level + "_");
353     }
354 
355     @Override
356     public void sectionTitle(int level, SinkEventAttributes attributes) {
357         addEvent("sectionTitle" + level, new Object[] {attributes});
358     }
359 
360     @Override
361     public void sectionTitle_(int level) {
362 
363         addEvent("sectionTitle" + level + "_");
364     }
365 
366     @Override
367     public void header(SinkEventAttributes attributes) {
368         addEvent("header", new Object[] {attributes});
369     }
370 
371     @Override
372     public void content(SinkEventAttributes attributes) {
373         addEvent("content", new Object[] {attributes});
374     }
375 
376     @Override
377     public void footer(SinkEventAttributes attributes) {
378         addEvent("footer", new Object[] {attributes});
379     }
380 
381     @Override
382     public void list(SinkEventAttributes attributes) {
383         addEvent("list", new Object[] {attributes});
384     }
385 
386     @Override
387     public void listItem(SinkEventAttributes attributes) {
388         addEvent("listItem", new Object[] {attributes});
389     }
390 
391     @Override
392     public void numberedList(int numbering, SinkEventAttributes attributes) {
393         addEvent("numberedList", new Object[] {numbering, attributes});
394     }
395 
396     @Override
397     public void numberedListItem(SinkEventAttributes attributes) {
398         addEvent("numberedListItem", new Object[] {attributes});
399     }
400 
401     @Override
402     public void definitionList(SinkEventAttributes attributes) {
403         addEvent("definitionList", new Object[] {attributes});
404     }
405 
406     @Override
407     public void definitionListItem(SinkEventAttributes attributes) {
408         addEvent("definitionListItem", new Object[] {attributes});
409     }
410 
411     @Override
412     public void definition(SinkEventAttributes attributes) {
413         addEvent("definition", new Object[] {attributes});
414     }
415 
416     @Override
417     public void definedTerm(SinkEventAttributes attributes) {
418         addEvent("definedTerm", new Object[] {attributes});
419     }
420 
421     @Override
422     public void figure(SinkEventAttributes attributes) {
423         addEvent("figure", new Object[] {attributes});
424     }
425 
426     @Override
427     public void figureCaption(SinkEventAttributes attributes) {
428         addEvent("figureCaption", new Object[] {attributes});
429     }
430 
431     @Override
432     public void figureGraphics(String src, SinkEventAttributes attributes) {
433         addEvent("figureGraphics", new Object[] {src, attributes});
434     }
435 
436     @Override
437     public void table(SinkEventAttributes attributes) {
438         addEvent("table", new Object[] {attributes});
439     }
440 
441     @Override
442     public void tableRow(SinkEventAttributes attributes) {
443         addEvent("tableRow", new Object[] {attributes});
444     }
445 
446     @Override
447     public void tableCell(SinkEventAttributes attributes) {
448         addEvent("tableCell", new Object[] {attributes});
449     }
450 
451     @Override
452     public void tableHeaderCell(SinkEventAttributes attributes) {
453         addEvent("tableHeaderCell", new Object[] {attributes});
454     }
455 
456     @Override
457     public void tableCaption(SinkEventAttributes attributes) {
458         addEvent("tableCaption", new Object[] {attributes});
459     }
460 
461     @Override
462     public void paragraph(SinkEventAttributes attributes) {
463         addEvent("paragraph", new Object[] {attributes});
464     }
465 
466     @Override
467     public void data(String value, SinkEventAttributes attributes) {
468         addEvent("data", new Object[] {value, attributes});
469     }
470 
471     @Override
472     public void time(String datetime, SinkEventAttributes attributes) {
473         addEvent("time", new Object[] {datetime, attributes});
474     }
475 
476     @Override
477     public void address(SinkEventAttributes attributes) {
478         addEvent("address", new Object[] {attributes});
479     }
480 
481     @Override
482     public void blockquote(SinkEventAttributes attributes) {
483         addEvent("blockquote", new Object[] {attributes});
484     }
485 
486     @Override
487     public void division(SinkEventAttributes attributes) {
488         addEvent("division", new Object[] {attributes});
489     }
490 
491     @Override
492     public void verbatim(SinkEventAttributes attributes) {
493         addEvent("verbatim", new Object[] {attributes});
494     }
495 
496     @Override
497     public void horizontalRule(SinkEventAttributes attributes) {
498         addEvent("horizontalRule", new Object[] {attributes});
499     }
500 
501     @Override
502     public void anchor(String name, SinkEventAttributes attributes) {
503         addEvent("anchor", new Object[] {name, attributes});
504     }
505 
506     @Override
507     public void link(String name, SinkEventAttributes attributes) {
508         addEvent("link", new Object[] {name, attributes});
509     }
510 
511     @Override
512     public void inline(SinkEventAttributes attributes) {
513         addEvent("inline", new Object[] {attributes});
514     }
515 
516     @Override
517     public void lineBreak(SinkEventAttributes attributes) {
518         addEvent("lineBreak", new Object[] {attributes});
519     }
520 
521     @Override
522     public void lineBreakOpportunity(SinkEventAttributes attributes) {
523         addEvent("lineBreakOpportunity", new Object[] {attributes});
524     }
525 
526     @Override
527     public void text(String text, SinkEventAttributes attributes) {
528         addEvent("text", new Object[] {text, attributes});
529     }
530 
531     @Override
532     public void unknown(String name, Object[] requiredParams, SinkEventAttributes attributes) {
533         addEvent("unknown", new Object[] {name, requiredParams, attributes});
534     }
535 
536     //
537     // private
538     //
539 
540     /**
541      * Adds a no-arg event to the list of events.
542      *
543      * @param string the name of the event.
544      */
545     private void addEvent(String string) {
546         addEvent(string, null);
547     }
548 
549     /**
550      * Adds an event to the list of events.
551      *
552      * @param string the name of the event.
553      * @param arguments The array of arguments to the sink method.
554      */
555     private void addEvent(String string, Object[] arguments) {
556         events.add(new SinkEventElement(string, arguments));
557     }
558 }