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
123   461   56   2.28
2   348   0.46   54
54     1.04  
1    
 
  EmptyBlockChainingListener       Line # 38 123 0% 56 0 100% 1.0
 
  (333)
 
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 org.xwiki.rendering.listener.MetaData;
23    import org.xwiki.rendering.syntax.Syntax;
24    import org.xwiki.rendering.listener.Format;
25    import org.xwiki.rendering.listener.reference.ResourceReference;
26    import org.xwiki.rendering.listener.ListType;
27    import org.xwiki.rendering.listener.HeaderLevel;
28   
29    import java.util.Map;
30    import java.util.Stack;
31   
32    /**
33    * Allow knowing if a container block (a block which can have children) has children or not.
34    *
35    * @version $Id: fc55804f86b3e4a16df0ea5218f91a10e9f96be9 $
36    * @since 2.0M3
37    */
 
38    public class EmptyBlockChainingListener extends AbstractChainingListener
39    {
40    private Stack<Boolean> containerBlockStates = new Stack<Boolean>();
41   
 
42  506 toggle public EmptyBlockChainingListener(ListenerChain listenerChain)
43    {
44  506 setListenerChain(listenerChain);
45    }
46   
 
47  105 toggle public boolean isCurrentContainerBlockEmpty()
48    {
49  105 return this.containerBlockStates.peek();
50    }
51   
52    // Events
53   
54    /**
55    * {@inheritDoc}
56    * @since 3.0M2
57    */
 
58  263 toggle @Override
59    public void beginDocument(MetaData metaData)
60    {
61  263 startContainerBlock();
62  263 super.beginDocument(metaData);
63    }
64   
 
65  25 toggle @Override
66    public void beginDefinitionDescription()
67    {
68  25 markNotEmpty();
69  25 startContainerBlock();
70  25 super.beginDefinitionDescription();
71    }
72   
73    /**
74    * {@inheritDoc}
75    * @since 2.0RC1
76    */
 
77  26 toggle @Override
78    public void beginDefinitionList(Map<String, String> parameters)
79    {
80  26 markNotEmpty();
81  26 startContainerBlock();
82  26 super.beginDefinitionList(parameters);
83    }
84   
 
85  21 toggle @Override
86    public void beginDefinitionTerm()
87    {
88  21 markNotEmpty();
89  21 startContainerBlock();
90  21 super.beginDefinitionTerm();
91    }
92   
 
93  25 toggle @Override
94    public void beginGroup(Map<String, String> parameters)
95    {
96  25 markNotEmpty();
97  25 startContainerBlock();
98  25 super.beginGroup(parameters);
99    }
100   
 
101  93 toggle @Override
102    public void beginFormat(Format format, Map<String, String> parameters)
103    {
104  93 markNotEmpty();
105  93 startContainerBlock();
106  93 super.beginFormat(format, parameters);
107    }
108   
109    /**
110    * {@inheritDoc}
111    * @since 2.5RC1
112    */
 
113  103 toggle @Override
114    public void beginLink(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
115    {
116  103 markNotEmpty();
117  103 startContainerBlock();
118  103 super.beginLink(reference, isFreeStandingURI, parameters);
119    }
120   
 
121  52 toggle @Override
122    public void beginList(ListType listType, Map<String, String> parameters)
123    {
124  52 markNotEmpty();
125  52 startContainerBlock();
126  52 super.beginList(listType, parameters);
127    }
128   
 
129  68 toggle @Override
130    public void beginListItem()
131    {
132  68 markNotEmpty();
133  68 startContainerBlock();
134  68 super.beginListItem();
135    }
136   
 
137  48 toggle @Override
138    public void beginMacroMarker(String name, Map<String, String> parameters, String content, boolean isInline)
139    {
140  48 markNotEmpty();
141  48 startContainerBlock();
142  48 super.beginMacroMarker(name, parameters, content, isInline);
143    }
144   
 
145  258 toggle @Override
146    public void beginParagraph(Map<String, String> parameters)
147    {
148  258 markNotEmpty();
149  258 startContainerBlock();
150  258 super.beginParagraph(parameters);
151    }
152   
 
153  10 toggle @Override
154    public void beginQuotation(Map<String, String> parameters)
155    {
156  10 markNotEmpty();
157  10 startContainerBlock();
158  10 super.beginQuotation(parameters);
159    }
160   
 
161  16 toggle @Override
162    public void beginQuotationLine()
163    {
164  16 markNotEmpty();
165  16 startContainerBlock();
166  16 super.beginQuotationLine();
167    }
168   
 
169  48 toggle @Override
170    public void beginHeader(HeaderLevel level, String id, Map<String, String> parameters)
171    {
172  48 markNotEmpty();
173  48 startContainerBlock();
174  48 super.beginHeader(level, id, parameters);
175    }
176   
 
177  16 toggle @Override
178    public void beginTable(Map<String, String> parameters)
179    {
180  16 markNotEmpty();
181  16 startContainerBlock();
182  16 super.beginTable(parameters);
183    }
184   
 
185  33 toggle @Override
186    public void beginTableRow(Map<String, String> parameters)
187    {
188  33 markNotEmpty();
189  33 startContainerBlock();
190  33 super.beginTableRow(parameters);
191    }
192   
 
193  42 toggle @Override
194    public void beginTableCell(Map<String, String> parameters)
195    {
196  42 markNotEmpty();
197  42 startContainerBlock();
198  42 super.beginTableCell(parameters);
199    }
200   
 
201  26 toggle @Override
202    public void beginTableHeadCell(Map<String, String> parameters)
203    {
204  26 markNotEmpty();
205  26 startContainerBlock();
206  26 super.beginTableHeadCell(parameters);
207    }
208   
 
209  55 toggle @Override
210    public void beginSection(Map<String, String> parameters)
211    {
212  55 markNotEmpty();
213  55 startContainerBlock();
214  55 super.beginSection(parameters);
215    }
216   
217    /**
218    * {@inheritDoc}
219    * @since 3.0M2
220    */
 
221  263 toggle @Override
222    public void endDocument(MetaData metaData)
223    {
224  263 super.endDocument(metaData);
225  263 stopContainerBlock();
226    }
227   
 
228  25 toggle @Override
229    public void endDefinitionDescription()
230    {
231  25 super.endDefinitionDescription();
232  25 stopContainerBlock();
233    }
234   
235    /**
236    * {@inheritDoc}
237    * @since 2.0RC1
238    */
 
239  26 toggle @Override
240    public void endDefinitionList(Map<String, String> parameters)
241    {
242  26 super.endDefinitionList(parameters);
243  26 stopContainerBlock();
244    }
245   
 
246  21 toggle @Override
247    public void endDefinitionTerm()
248    {
249  21 super.endDefinitionTerm();
250  21 stopContainerBlock();
251    }
252   
 
253  93 toggle @Override
254    public void endFormat(Format format, Map<String, String> parameters)
255    {
256  93 super.endFormat(format, parameters);
257  93 stopContainerBlock();
258    }
259   
 
260  25 toggle @Override
261    public void endGroup(Map<String, String> parameters)
262    {
263  25 super.endGroup(parameters);
264  25 stopContainerBlock();
265    }
266   
267    /**
268    * {@inheritDoc}
269    * @since 2.5RC1
270    */
 
271  103 toggle @Override
272    public void endLink(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
273    {
274  103 super.endLink(reference, isFreeStandingURI, parameters);
275  103 stopContainerBlock();
276    }
277   
 
278  52 toggle @Override
279    public void endList(ListType listType, Map<String, String> parameters)
280    {
281  52 super.endList(listType, parameters);
282  52 stopContainerBlock();
283    }
284   
 
285  68 toggle @Override
286    public void endListItem()
287    {
288  68 super.endListItem();
289  68 stopContainerBlock();
290    }
291   
 
292  48 toggle @Override
293    public void endMacroMarker(String name, Map<String, String> parameters, String content, boolean isInline)
294    {
295  48 super.endMacroMarker(name, parameters, content, isInline);
296  48 stopContainerBlock();
297    }
298   
 
299  258 toggle @Override
300    public void endParagraph(Map<String, String> parameters)
301    {
302  258 super.endParagraph(parameters);
303  258 stopContainerBlock();
304    }
305   
 
306  10 toggle @Override
307    public void endQuotation(Map<String, String> parameters)
308    {
309  10 super.endQuotation(parameters);
310  10 stopContainerBlock();
311    }
312   
 
313  16 toggle @Override
314    public void endQuotationLine()
315    {
316  16 super.endQuotationLine();
317  16 stopContainerBlock();
318    }
319   
 
320  55 toggle @Override
321    public void endSection(Map<String, String> parameters)
322    {
323  55 super.endSection(parameters);
324  55 stopContainerBlock();
325    }
326   
 
327  48 toggle @Override
328    public void endHeader(HeaderLevel level, String id, Map<String, String> parameters)
329    {
330  48 super.endHeader(level, id, parameters);
331  48 stopContainerBlock();
332    }
333   
 
334  16 toggle @Override
335    public void endTable(Map<String, String> parameters)
336    {
337  16 super.endTable(parameters);
338  16 stopContainerBlock();
339    }
340   
 
341  42 toggle @Override
342    public void endTableCell(Map<String, String> parameters)
343    {
344  42 super.endTableCell(parameters);
345  42 stopContainerBlock();
346    }
347   
 
348  26 toggle @Override
349    public void endTableHeadCell(Map<String, String> parameters)
350    {
351  26 super.endTableHeadCell(parameters);
352  26 stopContainerBlock();
353    }
354   
 
355  33 toggle @Override
356    public void endTableRow(Map<String, String> parameters)
357    {
358  33 super.endTableRow(parameters);
359  33 stopContainerBlock();
360    }
361   
 
362  14 toggle @Override
363    public void onRawText(String text, Syntax syntax)
364    {
365  14 super.onRawText(text, syntax);
366  14 markNotEmpty();
367    }
368   
 
369  8 toggle @Override
370    public void onEmptyLines(int count)
371    {
372  8 super.onEmptyLines(count);
373  8 markNotEmpty();
374    }
375   
 
376  11 toggle @Override
377    public void onHorizontalLine(Map<String, String> parameters)
378    {
379  11 super.onHorizontalLine(parameters);
380  11 markNotEmpty();
381    }
382   
 
383  3 toggle @Override
384    public void onId(String name)
385    {
386  3 super.onId(name);
387  3 markNotEmpty();
388    }
389   
390    /**
391    * {@inheritDoc}
392    * @since 2.5RC1
393    */
 
394  34 toggle @Override
395    public void onImage(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
396    {
397  34 super.onImage(reference, isFreeStandingURI, parameters);
398  34 markNotEmpty();
399    }
400   
 
401  119 toggle @Override
402    public void onNewLine()
403    {
404  119 super.onNewLine();
405  119 markNotEmpty();
406    }
407   
 
408  766 toggle @Override
409    public void onSpace()
410    {
411  766 super.onSpace();
412  766 markNotEmpty();
413    }
414   
 
415  306 toggle @Override
416    public void onSpecialSymbol(char symbol)
417    {
418  306 super.onSpecialSymbol(symbol);
419  306 markNotEmpty();
420    }
421   
 
422  23 toggle @Override
423    public void onVerbatim(String protectedString, boolean isInline, Map<String, String> parameters)
424    {
425  23 super.onVerbatim(protectedString, isInline, parameters);
426  23 markNotEmpty();
427    }
428   
 
429  1489 toggle @Override
430    public void onWord(String word)
431    {
432  1489 super.onWord(word);
433  1489 markNotEmpty();
434    }
435   
 
436  29 toggle @Override
437    public void onMacro(String id, Map<String, String> parameters, String content, boolean isInline)
438    {
439  29 super.onMacro(id, parameters, content, isInline);
440  29 markNotEmpty();
441    }
442   
 
443  1228 toggle private void startContainerBlock()
444    {
445  1228 this.containerBlockStates.push(Boolean.TRUE);
446    }
447   
 
448  1228 toggle private void stopContainerBlock()
449    {
450  1228 this.containerBlockStates.pop();
451    }
452   
 
453  3767 toggle private void markNotEmpty()
454    {
455  3767 if (!this.containerBlockStates.isEmpty() && this.containerBlockStates.peek()) {
456  1167 this.containerBlockStates.pop();
457  1167 this.containerBlockStates.push(Boolean.FALSE);
458    }
459    }
460   
461    }