1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.listener.chaining

File LookaheadChainingListener.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

4
112
56
1
480
348
58
0.52
2
56
1.04

Classes

Class Line # Actions
LookaheadChainingListener 40 112 0% 58 6
0.9651162696.5%
 

Contributing tests

This file is covered by 279 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.rendering.listener.chaining;
21   
22    import java.util.Map;
23   
24    import org.xwiki.rendering.listener.Format;
25    import org.xwiki.rendering.listener.HeaderLevel;
26    import org.xwiki.rendering.listener.ListType;
27    import org.xwiki.rendering.listener.MetaData;
28    import org.xwiki.rendering.listener.QueueListener;
29    import org.xwiki.rendering.listener.QueueListener.Event;
30    import org.xwiki.rendering.listener.reference.ResourceReference;
31    import org.xwiki.rendering.syntax.Syntax;
32   
33    /**
34    * Stores events without emitting them back in order to accumulate them and to provide a lookahead feature. The
35    * lookahead depth is configurable.
36    *
37    * @version $Id: 33da5830866540da461008c9ad447561e7b29fac $
38    * @since 1.8RC1
39    */
 
40    public class LookaheadChainingListener extends AbstractChainingListener
41    {
42    private QueueListener previousEvents = new QueueListener();
43   
44    private int lookaheadDepth;
45   
 
46  335 toggle public LookaheadChainingListener(ListenerChain listenerChain, int lookaheadDepth)
47    {
48  335 setListenerChain(listenerChain);
49  335 this.lookaheadDepth = lookaheadDepth;
50    }
51   
 
52  319 toggle public Event getNextEvent()
53    {
54  319 return getNextEvent(1);
55    }
56   
 
57  324 toggle public Event getNextEvent(int depth)
58    {
59  324 return this.previousEvents.getEvent(depth);
60    }
61   
 
62  21 toggle @Override
63    public void beginDefinitionDescription()
64    {
65  21 this.previousEvents.beginDefinitionDescription();
66  21 firePreviousEvent();
67    }
68   
69    /**
70    * {@inheritDoc}
71    *
72    * @since 2.0RC1
73    */
 
74  22 toggle @Override
75    public void beginDefinitionList(Map<String, String> parameters)
76    {
77  22 this.previousEvents.beginDefinitionList(parameters);
78  22 firePreviousEvent();
79    }
80   
 
81  17 toggle @Override
82    public void beginDefinitionTerm()
83    {
84  17 this.previousEvents.beginDefinitionTerm();
85  17 firePreviousEvent();
86    }
87   
88    /**
89    * {@inheritDoc}
90    *
91    * @since 3.0M2
92    */
 
93  297 toggle @Override
94    public void beginDocument(MetaData metadata)
95    {
96  297 this.previousEvents.beginDocument(metadata);
97  297 flush();
98    }
99   
 
100  29 toggle @Override
101    public void beginGroup(Map<String, String> parameters)
102    {
103  29 this.previousEvents.beginGroup(parameters);
104  29 firePreviousEvent();
105    }
106   
 
107  112 toggle @Override
108    public void beginFormat(Format format, Map<String, String> parameters)
109    {
110  112 this.previousEvents.beginFormat(format, parameters);
111  112 firePreviousEvent();
112    }
113   
 
114  60 toggle @Override
115    public void beginHeader(HeaderLevel level, String id, Map<String, String> parameters)
116    {
117  60 this.previousEvents.beginHeader(level, id, parameters);
118  60 firePreviousEvent();
119    }
120   
121    /**
122    * {@inheritDoc}
123    *
124    * @since 2.5RC1
125    */
 
126  93 toggle @Override
127    public void beginLink(ResourceReference reference, boolean freestanding, Map<String, String> parameters)
128    {
129  93 this.previousEvents.beginLink(reference, freestanding, parameters);
130  93 firePreviousEvent();
131    }
132   
 
133  64 toggle @Override
134    public void beginList(ListType type, Map<String, String> parameters)
135    {
136  64 this.previousEvents.beginList(type, parameters);
137  64 firePreviousEvent();
138    }
139   
 
140  94 toggle @Override
141    public void beginListItem()
142    {
143  94 this.previousEvents.beginListItem();
144  94 firePreviousEvent();
145    }
146   
 
147  25 toggle @Override
148    public void beginMacroMarker(String name, Map<String, String> parameters, String content, boolean isInline)
149    {
150  25 this.previousEvents.beginMacroMarker(name, parameters, content, isInline);
151  25 firePreviousEvent();
152    }
153   
154    /**
155    * {@inheritDoc}
156    *
157    * @since 3.0M2
158    */
 
159  0 toggle @Override
160    public void beginMetaData(MetaData metadata)
161    {
162  0 this.previousEvents.beginMetaData(metadata);
163  0 firePreviousEvent();
164    }
165   
 
166  286 toggle @Override
167    public void beginParagraph(Map<String, String> parameters)
168    {
169  286 this.previousEvents.beginParagraph(parameters);
170  286 firePreviousEvent();
171    }
172   
 
173  11 toggle @Override
174    public void beginQuotation(Map<String, String> parameters)
175    {
176  11 this.previousEvents.beginQuotation(parameters);
177  11 firePreviousEvent();
178    }
179   
 
180  17 toggle @Override
181    public void beginQuotationLine()
182    {
183  17 this.previousEvents.beginQuotationLine();
184  17 firePreviousEvent();
185    }
186   
 
187  65 toggle @Override
188    public void beginSection(Map<String, String> parameters)
189    {
190  65 this.previousEvents.beginSection(parameters);
191  65 firePreviousEvent();
192    }
193   
 
194  19 toggle @Override
195    public void beginTable(Map<String, String> parameters)
196    {
197  19 this.previousEvents.beginTable(parameters);
198  19 firePreviousEvent();
199    }
200   
 
201  44 toggle @Override
202    public void beginTableCell(Map<String, String> parameters)
203    {
204  44 this.previousEvents.beginTableCell(parameters);
205  44 firePreviousEvent();
206    }
207   
 
208  25 toggle @Override
209    public void beginTableHeadCell(Map<String, String> parameters)
210    {
211  25 this.previousEvents.beginTableHeadCell(parameters);
212  25 firePreviousEvent();
213    }
214   
 
215  34 toggle @Override
216    public void beginTableRow(Map<String, String> parameters)
217    {
218  34 this.previousEvents.beginTableRow(parameters);
219  34 firePreviousEvent();
220    }
221   
 
222  21 toggle @Override
223    public void endDefinitionDescription()
224    {
225  21 this.previousEvents.endDefinitionDescription();
226  21 firePreviousEvent();
227    }
228   
229    /**
230    * {@inheritDoc}
231    *
232    * @since 2.0RC1
233    */
 
234  22 toggle @Override
235    public void endDefinitionList(Map<String, String> parameters)
236    {
237  22 this.previousEvents.endDefinitionList(parameters);
238  22 firePreviousEvent();
239    }
240   
 
241  17 toggle @Override
242    public void endDefinitionTerm()
243    {
244  17 this.previousEvents.endDefinitionTerm();
245  17 firePreviousEvent();
246    }
247   
248    /**
249    * {@inheritDoc}
250    *
251    * @since 3.0M2
252    */
 
253  512 toggle @Override
254    public void endDocument(MetaData metadata)
255    {
256  512 this.previousEvents.endDocument(metadata);
257  512 flush();
258    }
259   
 
260  29 toggle @Override
261    public void endGroup(Map<String, String> parameters)
262    {
263  29 this.previousEvents.endGroup(parameters);
264  29 firePreviousEvent();
265    }
266   
 
267  112 toggle @Override
268    public void endFormat(Format format, Map<String, String> parameters)
269    {
270  112 this.previousEvents.endFormat(format, parameters);
271  112 firePreviousEvent();
272    }
273   
 
274  60 toggle @Override
275    public void endHeader(HeaderLevel level, String id, Map<String, String> parameters)
276    {
277  60 this.previousEvents.endHeader(level, id, parameters);
278  60 firePreviousEvent();
279    }
280   
281    /**
282    * {@inheritDoc}
283    *
284    * @since 2.5RC1
285    */
 
286  93 toggle @Override
287    public void endLink(ResourceReference reference, boolean freestanding, Map<String, String> parameters)
288    {
289  93 this.previousEvents.endLink(reference, freestanding, parameters);
290  93 firePreviousEvent();
291    }
292   
 
293  64 toggle @Override
294    public void endList(ListType type, Map<String, String> parameters)
295    {
296  64 this.previousEvents.endList(type, parameters);
297  64 firePreviousEvent();
298    }
299   
 
300  94 toggle @Override
301    public void endListItem()
302    {
303  94 this.previousEvents.endListItem();
304  94 firePreviousEvent();
305    }
306   
 
307  25 toggle @Override
308    public void endMacroMarker(String name, Map<String, String> parameters, String content, boolean isInline)
309    {
310  25 this.previousEvents.endMacroMarker(name, parameters, content, isInline);
311  25 firePreviousEvent();
312    }
313   
314    /**
315    * {@inheritDoc}
316    *
317    * @since 3.0M2
318    */
 
319  0 toggle @Override
320    public void endMetaData(MetaData metadata)
321    {
322  0 this.previousEvents.endMetaData(metadata);
323  0 firePreviousEvent();
324    }
325   
 
326  283 toggle @Override
327    public void endParagraph(Map<String, String> parameters)
328    {
329  283 this.previousEvents.endParagraph(parameters);
330  283 firePreviousEvent();
331    }
332   
 
333  11 toggle @Override
334    public void endQuotation(Map<String, String> parameters)
335    {
336  11 this.previousEvents.endQuotation(parameters);
337  11 firePreviousEvent();
338    }
339   
 
340  17 toggle @Override
341    public void endQuotationLine()
342    {
343  17 this.previousEvents.endQuotationLine();
344  17 firePreviousEvent();
345    }
346   
 
347  65 toggle @Override
348    public void endSection(Map<String, String> parameters)
349    {
350  65 this.previousEvents.endSection(parameters);
351  65 firePreviousEvent();
352    }
353   
 
354  19 toggle @Override
355    public void endTable(Map<String, String> parameters)
356    {
357  19 this.previousEvents.endTable(parameters);
358  19 firePreviousEvent();
359    }
360   
 
361  44 toggle @Override
362    public void endTableCell(Map<String, String> parameters)
363    {
364  44 this.previousEvents.endTableCell(parameters);
365  44 firePreviousEvent();
366    }
367   
 
368  25 toggle @Override
369    public void endTableHeadCell(Map<String, String> parameters)
370    {
371  25 this.previousEvents.endTableHeadCell(parameters);
372  25 firePreviousEvent();
373    }
374   
 
375  34 toggle @Override
376    public void endTableRow(Map<String, String> parameters)
377    {
378  34 this.previousEvents.endTableRow(parameters);
379  34 firePreviousEvent();
380    }
381   
 
382  4 toggle @Override
383    public void onRawText(String text, Syntax syntax)
384    {
385  4 this.previousEvents.onRawText(text, syntax);
386  4 firePreviousEvent();
387    }
388   
 
389  10 toggle @Override
390    public void onEmptyLines(int count)
391    {
392  10 this.previousEvents.onEmptyLines(count);
393  10 firePreviousEvent();
394    }
395   
 
396  10 toggle @Override
397    public void onHorizontalLine(Map<String, String> parameters)
398    {
399  10 this.previousEvents.onHorizontalLine(parameters);
400  10 firePreviousEvent();
401    }
402   
 
403  6 toggle @Override
404    public void onId(String name)
405    {
406  6 this.previousEvents.onId(name);
407  6 firePreviousEvent();
408    }
409   
410    /**
411    * {@inheritDoc}
412    *
413    * @since 2.5RC1
414    */
 
415  37 toggle @Override
416    public void onImage(ResourceReference reference, boolean freestanding, Map<String, String> parameters)
417    {
418  37 this.previousEvents.onImage(reference, freestanding, parameters);
419  37 firePreviousEvent();
420    }
421   
 
422  22 toggle @Override
423    public void onMacro(String id, Map<String, String> parameters, String content, boolean inline)
424    {
425  22 this.previousEvents.onMacro(id, parameters, content, inline);
426  22 firePreviousEvent();
427    }
428   
 
429  101 toggle @Override
430    public void onNewLine()
431    {
432  101 this.previousEvents.onNewLine();
433  101 firePreviousEvent();
434    }
435   
 
436  603 toggle @Override
437    public void onSpace()
438    {
439  603 this.previousEvents.onSpace();
440  603 firePreviousEvent();
441    }
442   
 
443  276 toggle @Override
444    public void onSpecialSymbol(char symbol)
445    {
446  276 this.previousEvents.onSpecialSymbol(symbol);
447  276 firePreviousEvent();
448    }
449   
 
450  20 toggle @Override
451    public void onVerbatim(String content, boolean inline, Map<String, String> parameters)
452    {
453  20 this.previousEvents.onVerbatim(content, inline, parameters);
454  20 firePreviousEvent();
455    }
456   
 
457  1069 toggle @Override
458    public void onWord(String word)
459    {
460  1069 this.previousEvents.onWord(word);
461  1069 firePreviousEvent();
462    }
463   
 
464  4231 toggle private void firePreviousEvent()
465    {
466  4231 if (this.previousEvents.size() > this.lookaheadDepth) {
467  3657 Event event = this.previousEvents.remove();
468  3657 event.eventType.fireEvent(getListenerChain().getNextListener(getClass()), event.eventParameters);
469    }
470    }
471   
 
472  809 toggle private void flush()
473    {
474    // Ensure that all remaining events are flushed
475  2188 while (!this.previousEvents.isEmpty()) {
476  1379 Event event = this.previousEvents.remove();
477  1379 event.eventType.fireEvent(getListenerChain().getNextListener(getClass()), event.eventParameters);
478    }
479    }
480    }