Clover Coverage Report - XWiki Rendering - Parent POM 4.0-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Mar 12 2012 18:03:13 CET
../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
112   471   58   2
4   348   0.52   56
56     1.04  
1    
 
  LookaheadChainingListener       Line # 40 112 0% 58 6 96.5% 0.96511626
 
  (326)
 
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.MetaData;
27    import org.xwiki.rendering.listener.reference.ResourceReference;
28    import org.xwiki.rendering.listener.ListType;
29    import org.xwiki.rendering.listener.QueueListener;
30    import org.xwiki.rendering.listener.QueueListener.Event;
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: 20731c1158992c3b4db7ca8e7e4c030618409abd $
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  347 toggle public LookaheadChainingListener(ListenerChain listenerChain, int lookaheadDepth)
47    {
48  347 setListenerChain(listenerChain);
49  347 this.lookaheadDepth = lookaheadDepth;
50    }
51   
 
52  281 toggle public Event getNextEvent()
53    {
54  281 return getNextEvent(1);
55    }
56   
 
57  286 toggle public Event getNextEvent(int depth)
58    {
59  286 return this.previousEvents.getEvent(depth);
60    }
61   
 
62  18 toggle @Override
63    public void beginDefinitionDescription()
64    {
65  18 this.previousEvents.beginDefinitionDescription();
66  18 firePreviousEvent();
67    }
68   
69    /**
70    * {@inheritDoc}
71    * @since 2.0RC1
72    */
 
73  20 toggle @Override
74    public void beginDefinitionList(Map<String, String> parameters)
75    {
76  20 this.previousEvents.beginDefinitionList(parameters);
77  20 firePreviousEvent();
78    }
79   
 
80  14 toggle @Override
81    public void beginDefinitionTerm()
82    {
83  14 this.previousEvents.beginDefinitionTerm();
84  14 firePreviousEvent();
85    }
86   
87    /**
88    * {@inheritDoc}
89    * @since 3.0M2
90    */
 
91  399 toggle @Override
92    public void beginDocument(MetaData metaData)
93    {
94  399 this.previousEvents.beginDocument(metaData);
95  399 flush();
96    }
97   
 
98  33 toggle @Override
99    public void beginGroup(Map<String, String> parameters)
100    {
101  33 this.previousEvents.beginGroup(parameters);
102  33 firePreviousEvent();
103    }
104   
 
105  86 toggle @Override
106    public void beginFormat(Format format, Map<String, String> parameters)
107    {
108  86 this.previousEvents.beginFormat(format, parameters);
109  86 firePreviousEvent();
110    }
111   
 
112  50 toggle @Override
113    public void beginHeader(HeaderLevel level, String id, Map<String, String> parameters)
114    {
115  50 this.previousEvents.beginHeader(level, id, parameters);
116  50 firePreviousEvent();
117    }
118   
119    /**
120    * {@inheritDoc}
121    * @since 2.5RC1
122    */
 
123  78 toggle @Override
124    public void beginLink(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
125    {
126  78 this.previousEvents.beginLink(reference, isFreeStandingURI, parameters);
127  78 firePreviousEvent();
128    }
129   
 
130  66 toggle @Override
131    public void beginList(ListType listType, Map<String, String> parameters)
132    {
133  66 this.previousEvents.beginList(listType, parameters);
134  66 firePreviousEvent();
135    }
136   
 
137  76 toggle @Override
138    public void beginListItem()
139    {
140  76 this.previousEvents.beginListItem();
141  76 firePreviousEvent();
142    }
143   
 
144  24 toggle @Override
145    public void beginMacroMarker(String name, Map<String, String> parameters, String content, boolean isInline)
146    {
147  24 this.previousEvents.beginMacroMarker(name, parameters, content, isInline);
148  24 firePreviousEvent();
149    }
150   
151    /**
152    * {@inheritDoc}
153    * @since 3.0M2
154    */
 
155  0 toggle @Override
156    public void beginMetaData(MetaData metadata)
157    {
158  0 this.previousEvents.beginMetaData(metadata);
159  0 firePreviousEvent();
160    }
161   
 
162  285 toggle @Override
163    public void beginParagraph(Map<String, String> parameters)
164    {
165  285 this.previousEvents.beginParagraph(parameters);
166  285 firePreviousEvent();
167    }
168   
 
169  9 toggle @Override
170    public void beginQuotation(Map<String, String> parameters)
171    {
172  9 this.previousEvents.beginQuotation(parameters);
173  9 firePreviousEvent();
174    }
175   
 
176  16 toggle @Override
177    public void beginQuotationLine()
178    {
179  16 this.previousEvents.beginQuotationLine();
180  16 firePreviousEvent();
181    }
182   
 
183  55 toggle @Override
184    public void beginSection(Map<String, String> parameters)
185    {
186  55 this.previousEvents.beginSection(parameters);
187  55 firePreviousEvent();
188    }
189   
 
190  21 toggle @Override
191    public void beginTable(Map<String, String> parameters)
192    {
193  21 this.previousEvents.beginTable(parameters);
194  21 firePreviousEvent();
195    }
196   
 
197  53 toggle @Override
198    public void beginTableCell(Map<String, String> parameters)
199    {
200  53 this.previousEvents.beginTableCell(parameters);
201  53 firePreviousEvent();
202    }
203   
 
204  31 toggle @Override
205    public void beginTableHeadCell(Map<String, String> parameters)
206    {
207  31 this.previousEvents.beginTableHeadCell(parameters);
208  31 firePreviousEvent();
209    }
210   
 
211  39 toggle @Override
212    public void beginTableRow(Map<String, String> parameters)
213    {
214  39 this.previousEvents.beginTableRow(parameters);
215  39 firePreviousEvent();
216    }
217   
 
218  18 toggle @Override
219    public void endDefinitionDescription()
220    {
221  18 this.previousEvents.endDefinitionDescription();
222  18 firePreviousEvent();
223    }
224   
225    /**
226    * {@inheritDoc}
227    * @since 2.0RC1
228    */
 
229  20 toggle @Override
230    public void endDefinitionList(Map<String, String> parameters)
231    {
232  20 this.previousEvents.endDefinitionList(parameters);
233  20 firePreviousEvent();
234    }
235   
 
236  14 toggle @Override
237    public void endDefinitionTerm()
238    {
239  14 this.previousEvents.endDefinitionTerm();
240  14 firePreviousEvent();
241    }
242   
243    /**
244    * {@inheritDoc}
245    * @since 3.0M2
246    */
 
247  399 toggle @Override
248    public void endDocument(MetaData metaData)
249    {
250  399 this.previousEvents.endDocument(metaData);
251  399 flush();
252    }
253   
 
254  33 toggle @Override
255    public void endGroup(Map<String, String> parameters)
256    {
257  33 this.previousEvents.endGroup(parameters);
258  33 firePreviousEvent();
259    }
260   
 
261  86 toggle @Override
262    public void endFormat(Format format, Map<String, String> parameters)
263    {
264  86 this.previousEvents.endFormat(format, parameters);
265  86 firePreviousEvent();
266    }
267   
 
268  50 toggle @Override
269    public void endHeader(HeaderLevel level, String id, Map<String, String> parameters)
270    {
271  50 this.previousEvents.endHeader(level, id, parameters);
272  50 firePreviousEvent();
273    }
274   
275    /**
276    * {@inheritDoc}
277    * @since 2.5RC1
278    */
 
279  78 toggle @Override
280    public void endLink(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
281    {
282  78 this.previousEvents.endLink(reference, isFreeStandingURI, parameters);
283  78 firePreviousEvent();
284    }
285   
 
286  66 toggle @Override
287    public void endList(ListType listType, Map<String, String> parameters)
288    {
289  66 this.previousEvents.endList(listType, parameters);
290  66 firePreviousEvent();
291    }
292   
 
293  76 toggle @Override
294    public void endListItem()
295    {
296  76 this.previousEvents.endListItem();
297  76 firePreviousEvent();
298    }
299   
 
300  24 toggle @Override
301    public void endMacroMarker(String name, Map<String, String> parameters, String content, boolean isInline)
302    {
303  24 this.previousEvents.endMacroMarker(name, parameters, content, isInline);
304  24 firePreviousEvent();
305    }
306   
307    /**
308    * {@inheritDoc}
309    * @since 3.0M2
310    */
 
311  0 toggle @Override
312    public void endMetaData(MetaData metadata)
313    {
314  0 this.previousEvents.endMetaData(metadata);
315  0 firePreviousEvent();
316    }
317   
 
318  284 toggle @Override
319    public void endParagraph(Map<String, String> parameters)
320    {
321  284 this.previousEvents.endParagraph(parameters);
322  284 firePreviousEvent();
323    }
324   
 
325  9 toggle @Override
326    public void endQuotation(Map<String, String> parameters)
327    {
328  9 this.previousEvents.endQuotation(parameters);
329  9 firePreviousEvent();
330    }
331   
 
332  16 toggle @Override
333    public void endQuotationLine()
334    {
335  16 this.previousEvents.endQuotationLine();
336  16 firePreviousEvent();
337    }
338   
 
339  55 toggle @Override
340    public void endSection(Map<String, String> parameters)
341    {
342  55 this.previousEvents.endSection(parameters);
343  55 firePreviousEvent();
344    }
345   
 
346  21 toggle @Override
347    public void endTable(Map<String, String> parameters)
348    {
349  21 this.previousEvents.endTable(parameters);
350  21 firePreviousEvent();
351    }
352   
 
353  53 toggle @Override
354    public void endTableCell(Map<String, String> parameters)
355    {
356  53 this.previousEvents.endTableCell(parameters);
357  53 firePreviousEvent();
358    }
359   
 
360  31 toggle @Override
361    public void endTableHeadCell(Map<String, String> parameters)
362    {
363  31 this.previousEvents.endTableHeadCell(parameters);
364  31 firePreviousEvent();
365    }
366   
 
367  39 toggle @Override
368    public void endTableRow(Map<String, String> parameters)
369    {
370  39 this.previousEvents.endTableRow(parameters);
371  39 firePreviousEvent();
372    }
373   
 
374  5 toggle @Override
375    public void onRawText(String text, Syntax syntax)
376    {
377  5 this.previousEvents.onRawText(text, syntax);
378  5 firePreviousEvent();
379    }
380   
 
381  8 toggle @Override
382    public void onEmptyLines(int count)
383    {
384  8 this.previousEvents.onEmptyLines(count);
385  8 firePreviousEvent();
386    }
387   
 
388  13 toggle @Override
389    public void onHorizontalLine(Map<String, String> parameters)
390    {
391  13 this.previousEvents.onHorizontalLine(parameters);
392  13 firePreviousEvent();
393    }
394   
 
395  6 toggle @Override
396    public void onId(String name)
397    {
398  6 this.previousEvents.onId(name);
399  6 firePreviousEvent();
400    }
401   
402    /**
403    * {@inheritDoc}
404    * @since 2.5RC1
405    */
 
406  39 toggle @Override
407    public void onImage(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
408    {
409  39 this.previousEvents.onImage(reference, isFreeStandingURI, parameters);
410  39 firePreviousEvent();
411    }
412   
 
413  107 toggle @Override
414    public void onMacro(String id, Map<String, String> parameters, String content, boolean isInline)
415    {
416  107 this.previousEvents.onMacro(id, parameters, content, isInline);
417  107 firePreviousEvent();
418    }
419   
 
420  90 toggle @Override
421    public void onNewLine()
422    {
423  90 this.previousEvents.onNewLine();
424  90 firePreviousEvent();
425    }
426   
 
427  552 toggle @Override
428    public void onSpace()
429    {
430  552 this.previousEvents.onSpace();
431  552 firePreviousEvent();
432    }
433   
 
434  289 toggle @Override
435    public void onSpecialSymbol(char symbol)
436    {
437  289 this.previousEvents.onSpecialSymbol(symbol);
438  289 firePreviousEvent();
439    }
440   
 
441  20 toggle @Override
442    public void onVerbatim(String protectedString, boolean isInline, Map<String, String> parameters)
443    {
444  20 this.previousEvents.onVerbatim(protectedString, isInline, parameters);
445  20 firePreviousEvent();
446    }
447   
 
448  1004 toggle @Override
449    public void onWord(String word)
450    {
451  1004 this.previousEvents.onWord(word);
452  1004 firePreviousEvent();
453    }
454   
 
455  4080 toggle private void firePreviousEvent()
456    {
457  4080 if (this.previousEvents.size() > this.lookaheadDepth) {
458  3490 Event event = this.previousEvents.remove();
459  3490 event.eventType.fireEvent(getListenerChain().getNextListener(getClass()), event.eventParameters);
460    }
461    }
462   
 
463  798 toggle private void flush()
464    {
465    // Ensure that all remaining events are flushed
466  2186 while (!this.previousEvents.isEmpty()) {
467  1388 Event event = this.previousEvents.remove();
468  1388 event.eventType.fireEvent(getListenerChain().getNextListener(getClass()), event.eventParameters);
469    }
470    }
471    }