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
150   670   75   2.08
6   481   0.5   18
72     1.04  
4    
 
  BlockStateChainingListener       Line # 38 150 0% 75 12 94.7% 0.94736844
  BlockStateChainingListener.Event       Line # 40 0 - 0 0 - -1.0
  BlockStateChainingListener.ListState       Line # 661 0 - 0 0 - -1.0
  BlockStateChainingListener.DefinitionListState       Line # 666 0 - 0 0 - -1.0
 
  (631)
 
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    import java.util.Stack;
24   
25    import org.xwiki.rendering.listener.Format;
26    import org.xwiki.rendering.listener.HeaderLevel;
27    import org.xwiki.rendering.listener.MetaData;
28    import org.xwiki.rendering.listener.reference.ResourceReference;
29    import org.xwiki.rendering.listener.ListType;
30    import org.xwiki.rendering.syntax.Syntax;
31   
32    /**
33    * Indicates block element for which we are inside and previous blocks.
34    *
35    * @version $Id: b91808752c3a57d873c18d9562a9664ebc92b817 $
36    * @since 1.8RC1
37    */
 
38    public class BlockStateChainingListener extends AbstractChainingListener implements StackableChainingListener
39    {
 
40    public enum Event
41    {
42    NONE,
43    DEFINITION_DESCRIPTION,
44    DEFINITION_TERM,
45    DEFINITION_LIST,
46    DOCUMENT,
47    FORMAT,
48    HEADER,
49    LINK,
50    LIST,
51    LIST_ITEM,
52    MACRO_MARKER,
53    PARAGRAPH,
54    QUOTATION,
55    QUOTATION_LINE,
56    SECTION,
57    TABLE,
58    TABLE_CELL,
59    TABLE_HEAD_CELL,
60    TABLE_ROW,
61    RAW_TEXT,
62    EMPTY_LINES,
63    HORIZONTAL_LINE,
64    ID,
65    IMAGE,
66    NEW_LINE,
67    SPACE,
68    SPECIAL_SYMBOL,
69    MACRO,
70    VERBATIM_INLINE,
71    VERBATIM_STANDALONE,
72    WORD
73    }
74   
75    private Event previousEvent = Event.NONE;
76   
77    private int inlineDepth;
78   
79    private boolean isInParagraph;
80   
81    private boolean isInHeader;
82   
83    private int linkDepth;
84   
85    private boolean isInTable;
86   
87    private boolean isInTableCell;
88   
89    private Stack<DefinitionListState> definitionListDepth = new Stack<DefinitionListState>();
90   
91    private Stack<ListState> listDepth = new Stack<ListState>();
92   
93    private int quotationDepth;
94   
95    private int quotationLineDepth;
96   
97    private int quotationLineIndex = -1;
98   
99    private int macroDepth;
100   
101    private int cellRow = -1;
102   
103    private int cellCol = -1;
104   
 
105  883 toggle public BlockStateChainingListener(ListenerChain listenerChain)
106    {
107  883 setListenerChain(listenerChain);
108    }
109   
 
110  33 toggle @Override
111    public StackableChainingListener createChainingListenerInstance()
112    {
113  33 return new BlockStateChainingListener(getListenerChain());
114    }
115   
 
116  12 toggle public Event getPreviousEvent()
117    {
118  12 return this.previousEvent;
119    }
120   
 
121  766 toggle public int getInlineDepth()
122    {
123  766 return this.inlineDepth;
124    }
125   
 
126  766 toggle public boolean isInLine()
127    {
128  766 return getInlineDepth() > 0;
129    }
130   
 
131  0 toggle public boolean isInParagraph()
132    {
133  0 return this.isInParagraph;
134    }
135   
 
136  640 toggle public boolean isInHeader()
137    {
138  640 return this.isInHeader;
139    }
140   
 
141  640 toggle public boolean isInTable()
142    {
143  640 return this.isInTable;
144    }
145   
 
146  0 toggle public boolean isInTableCell()
147    {
148  0 return this.isInTableCell;
149    }
150   
 
151  16 toggle public int getCellCol()
152    {
153  16 return this.cellCol;
154    }
155   
 
156  66 toggle public int getCellRow()
157    {
158  66 return this.cellRow;
159    }
160   
 
161  107 toggle public int getDefinitionListDepth()
162    {
163  107 return this.definitionListDepth.size();
164    }
165   
 
166  48 toggle public boolean isInDefinitionList()
167    {
168  48 return getDefinitionListDepth() > 0;
169    }
170   
 
171  48 toggle public int getDefinitionListItemIndex()
172    {
173  48 return isInDefinitionList() ? this.definitionListDepth.peek().definitionListItemIndex : -1;
174    }
175   
 
176  189 toggle public int getListDepth()
177    {
178  189 return this.listDepth.size();
179    }
180   
 
181  112 toggle public boolean isInList()
182    {
183  112 return getListDepth() > 0;
184    }
185   
 
186  92 toggle public int getListItemIndex()
187    {
188  92 return isInList() ? this.listDepth.peek().listItemIndex : -1;
189    }
190   
 
191  0 toggle public void pushLinkDepth()
192    {
193  0 ++this.linkDepth;
194    }
195   
 
196  0 toggle public void popLinkDepth()
197    {
198  0 --this.linkDepth;
199    }
200   
 
201  796 toggle public int getLinkDepth()
202    {
203  796 return this.linkDepth;
204    }
205   
 
206  0 toggle public boolean isInLink()
207    {
208  0 return getLinkDepth() > 0;
209    }
210   
 
211  28 toggle public int getQuotationDepth()
212    {
213  28 return this.quotationDepth;
214    }
215   
 
216  12 toggle public boolean isInQuotation()
217    {
218  12 return getQuotationDepth() > 0;
219    }
220   
 
221  23 toggle public int getQuotationLineDepth()
222    {
223  23 return this.quotationLineDepth;
224    }
225   
 
226  23 toggle public boolean isInQuotationLine()
227    {
228  23 return getQuotationLineDepth() > 0;
229    }
230   
 
231  20 toggle public int getQuotationLineIndex()
232    {
233  20 return this.quotationLineIndex;
234    }
235   
 
236  258 toggle public int getMacroDepth()
237    {
238  258 return this.macroDepth;
239    }
240   
 
241  234 toggle public boolean isInMacro()
242    {
243  234 return getMacroDepth() > 0;
244    }
245   
246    // Events
247   
 
248  43 toggle @Override
249    public void beginDefinitionDescription()
250    {
251  43 ++this.inlineDepth;
252  43 ++this.definitionListDepth.peek().definitionListItemIndex;
253   
254  43 super.beginDefinitionDescription();
255    }
256   
257    /**
258    * {@inheritDoc}
259    * @since 2.0RC1
260    */
 
261  46 toggle @Override
262    public void beginDefinitionList(Map<String, String> parameters)
263    {
264  46 this.definitionListDepth.push(new DefinitionListState());
265   
266  46 super.beginDefinitionList(parameters);
267    }
268   
 
269  35 toggle @Override
270    public void beginDefinitionTerm()
271    {
272  35 ++this.inlineDepth;
273  35 ++this.definitionListDepth.peek().definitionListItemIndex;
274   
275  35 super.beginDefinitionTerm();
276    }
277   
278    /**
279    * {@inheritDoc}
280    * @since 2.5RC1
281    */
 
282  181 toggle @Override
283    public void beginLink(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
284    {
285  181 ++this.linkDepth;
286   
287  181 super.beginLink(reference, isFreeStandingURI, parameters);
288    }
289   
 
290  118 toggle @Override
291    public void beginList(ListType listType, Map<String, String> parameters)
292    {
293  118 this.listDepth.push(new ListState());
294   
295  118 super.beginList(listType, parameters);
296    }
297   
 
298  144 toggle @Override
299    public void beginListItem()
300    {
301  144 ++this.inlineDepth;
302  144 ++this.listDepth.peek().listItemIndex;
303   
304  144 super.beginListItem();
305    }
306   
 
307  72 toggle @Override
308    public void beginMacroMarker(String name, Map<String, String> parameters, String content, boolean isInline)
309    {
310  72 ++this.macroDepth;
311   
312  72 super.beginMacroMarker(name, parameters, content, isInline);
313    }
314   
 
315  539 toggle @Override
316    public void beginParagraph(Map<String, String> parameters)
317    {
318  539 this.isInParagraph = true;
319  539 ++this.inlineDepth;
320   
321  539 super.beginParagraph(parameters);
322    }
323   
 
324  19 toggle @Override
325    public void beginQuotation(Map<String, String> parameters)
326    {
327  19 ++this.quotationDepth;
328   
329  19 super.beginQuotation(parameters);
330    }
331   
 
332  32 toggle @Override
333    public void beginQuotationLine()
334    {
335  32 ++this.quotationLineDepth;
336  32 ++this.inlineDepth;
337  32 ++this.quotationLineIndex;
338   
339  32 super.beginQuotationLine();
340    }
341   
 
342  98 toggle @Override
343    public void beginHeader(HeaderLevel level, String id, Map<String, String> parameters)
344    {
345  98 this.isInHeader = true;
346  98 ++this.inlineDepth;
347   
348  98 super.beginHeader(level, id, parameters);
349    }
350   
 
351  37 toggle @Override
352    public void beginTable(Map<String, String> parameters)
353    {
354  37 this.isInTable = true;
355   
356  37 super.beginTable(parameters);
357    }
358   
 
359  72 toggle @Override
360    public void beginTableRow(Map<String, String> parameters)
361    {
362  72 ++this.cellRow;
363   
364  72 super.beginTableRow(parameters);
365    }
366   
 
367  95 toggle @Override
368    public void beginTableCell(Map<String, String> parameters)
369    {
370  95 this.isInTableCell = true;
371  95 ++this.inlineDepth;
372  95 ++this.cellCol;
373   
374  95 super.beginTableCell(parameters);
375    }
376   
 
377  57 toggle @Override
378    public void beginTableHeadCell(Map<String, String> parameters)
379    {
380  57 this.isInTableCell = true;
381  57 ++this.inlineDepth;
382  57 ++this.cellCol;
383   
384  57 super.beginTableHeadCell(parameters);
385    }
386   
 
387  43 toggle @Override
388    public void endDefinitionDescription()
389    {
390  43 super.endDefinitionDescription();
391   
392  43 --this.inlineDepth;
393  43 this.previousEvent = Event.DEFINITION_DESCRIPTION;
394    }
395   
396    /**
397    * {@inheritDoc}
398    * @since 2.0RC1
399    */
 
400  46 toggle @Override
401    public void endDefinitionList(Map<String, String> parameters)
402    {
403  46 super.endDefinitionList(parameters);
404   
405  46 this.definitionListDepth.pop();
406   
407  46 this.previousEvent = Event.DEFINITION_LIST;
408    }
409   
 
410  35 toggle @Override
411    public void endDefinitionTerm()
412    {
413  35 super.endDefinitionTerm();
414   
415  35 --this.inlineDepth;
416  35 this.previousEvent = Event.DEFINITION_TERM;
417    }
418   
419    /**
420    * {@inheritDoc}
421    * @since 3.0M2
422    */
 
423  661 toggle @Override
424    public void endDocument(MetaData metaData)
425    {
426  661 this.previousEvent = Event.DOCUMENT;
427   
428  661 super.endDocument(metaData);
429    }
430   
 
431  179 toggle @Override
432    public void endFormat(Format format, Map<String, String> parameters)
433    {
434  179 super.endFormat(format, parameters);
435   
436  179 this.previousEvent = Event.FORMAT;
437    }
438   
439    /**
440    * {@inheritDoc}
441    * @since 2.5RC1
442    */
 
443  181 toggle @Override
444    public void endLink(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
445    {
446  181 super.endLink(reference, isFreeStandingURI, parameters);
447   
448  181 --this.linkDepth;
449  181 this.previousEvent = Event.LINK;
450    }
451   
 
452  118 toggle @Override
453    public void endList(ListType listType, Map<String, String> parameters)
454    {
455  118 super.endList(listType, parameters);
456   
457  118 this.listDepth.pop();
458   
459  118 this.previousEvent = Event.LIST;
460    }
461   
 
462  144 toggle @Override
463    public void endListItem()
464    {
465  144 super.endListItem();
466   
467  144 --this.inlineDepth;
468  144 this.previousEvent = Event.LIST_ITEM;
469    }
470   
 
471  72 toggle @Override
472    public void endMacroMarker(String name, Map<String, String> parameters, String content, boolean isInline)
473    {
474  72 super.endMacroMarker(name, parameters, content, isInline);
475   
476  72 this.previousEvent = Event.MACRO_MARKER;
477  72 --this.macroDepth;
478    }
479   
 
480  539 toggle @Override
481    public void endParagraph(Map<String, String> parameters)
482    {
483  539 super.endParagraph(parameters);
484   
485  539 this.isInParagraph = false;
486  539 --this.inlineDepth;
487  539 this.previousEvent = Event.PARAGRAPH;
488    }
489   
 
490  19 toggle @Override
491    public void endQuotation(Map<String, String> parameters)
492    {
493  19 super.endQuotation(parameters);
494   
495  19 --this.quotationDepth;
496  19 if (this.quotationDepth == 0) {
497  13 this.quotationLineIndex = -1;
498    }
499  19 this.previousEvent = Event.QUOTATION;
500    }
501   
 
502  32 toggle @Override
503    public void endQuotationLine()
504    {
505  32 super.endQuotationLine();
506   
507  32 --this.quotationLineDepth;
508  32 --this.inlineDepth;
509  32 this.previousEvent = Event.QUOTATION_LINE;
510    }
511   
 
512  110 toggle @Override
513    public void endSection(Map<String, String> parameters)
514    {
515  110 super.endSection(parameters);
516   
517  110 this.previousEvent = Event.SECTION;
518    }
519   
 
520  98 toggle @Override
521    public void endHeader(HeaderLevel level, String id, Map<String, String> parameters)
522    {
523  98 super.endHeader(level, id, parameters);
524   
525  98 this.isInHeader = false;
526  98 --this.inlineDepth;
527  98 this.previousEvent = Event.HEADER;
528    }
529   
 
530  37 toggle @Override
531    public void endTable(Map<String, String> parameters)
532    {
533  37 super.endTable(parameters);
534   
535  37 this.isInTable = false;
536  37 this.cellRow = -1;
537  37 this.previousEvent = Event.TABLE;
538    }
539   
 
540  95 toggle @Override
541    public void endTableCell(Map<String, String> parameters)
542    {
543  95 super.endTableCell(parameters);
544   
545  95 this.isInTableCell = false;
546  95 --this.inlineDepth;
547  95 this.previousEvent = Event.TABLE_CELL;
548    }
549   
 
550  57 toggle @Override
551    public void endTableHeadCell(Map<String, String> parameters)
552    {
553  57 super.endTableHeadCell(parameters);
554   
555  57 this.isInTableCell = false;
556  57 --this.inlineDepth;
557  57 this.previousEvent = Event.TABLE_HEAD_CELL;
558    }
559   
 
560  72 toggle @Override
561    public void endTableRow(Map<String, String> parameters)
562    {
563  72 super.endTableRow(parameters);
564   
565  72 this.previousEvent = Event.TABLE_ROW;
566  72 this.cellCol = -1;
567    }
568   
 
569  19 toggle @Override
570    public void onRawText(String text, Syntax syntax)
571    {
572  19 super.onRawText(text, syntax);
573   
574  19 this.previousEvent = Event.RAW_TEXT;
575    }
576   
 
577  16 toggle @Override
578    public void onEmptyLines(int count)
579    {
580  16 this.previousEvent = Event.EMPTY_LINES;
581   
582  16 super.onEmptyLines(count);
583    }
584   
 
585  24 toggle @Override
586    public void onHorizontalLine(Map<String, String> parameters)
587    {
588  24 this.previousEvent = Event.HORIZONTAL_LINE;
589   
590  24 super.onHorizontalLine(parameters);
591    }
592   
 
593  9 toggle @Override
594    public void onId(String name)
595    {
596  9 this.previousEvent = Event.ID;
597   
598  9 super.onId(name);
599    }
600   
601    /**
602    * {@inheritDoc}
603    * @since 2.5RC1
604    */
 
605  73 toggle @Override
606    public void onImage(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
607    {
608  73 this.previousEvent = Event.IMAGE;
609   
610  73 super.onImage(reference, isFreeStandingURI, parameters);
611    }
612   
 
613  209 toggle @Override
614    public void onNewLine()
615    {
616  209 this.previousEvent = Event.NEW_LINE;
617   
618  209 super.onNewLine();
619    }
620   
 
621  1318 toggle @Override
622    public void onSpace()
623    {
624  1318 this.previousEvent = Event.SPACE;
625   
626  1318 super.onSpace();
627    }
628   
 
629  595 toggle @Override
630    public void onSpecialSymbol(char symbol)
631    {
632  595 this.previousEvent = Event.SPECIAL_SYMBOL;
633   
634  595 super.onSpecialSymbol(symbol);
635    }
636   
 
637  43 toggle @Override
638    public void onVerbatim(String protectedString, boolean isInline, Map<String, String> parameters)
639    {
640  43 this.previousEvent = Event.VERBATIM_STANDALONE;
641   
642  43 super.onVerbatim(protectedString, isInline, parameters);
643    }
644   
 
645  2492 toggle @Override
646    public void onWord(String word)
647    {
648  2492 this.previousEvent = Event.WORD;
649   
650  2492 super.onWord(word);
651    }
652   
 
653  136 toggle @Override
654    public void onMacro(String id, Map<String, String> parameters, String content, boolean isInline)
655    {
656  136 this.previousEvent = Event.MACRO;
657   
658  136 super.onMacro(id, parameters, content, isInline);
659    }
660   
 
661    private static class ListState
662    {
663    public int listItemIndex = -1;
664    }
665   
 
666    private static class DefinitionListState
667    {
668    public int definitionListItemIndex = -1;
669    }
670    }