Clover Coverage Report - XWiki Rendering - Parent POM 4.0-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Mar 12 2012 18:03:13 CET
../../../../../img/srcFileCovDistChart9.png 55% of files have more coverage
65   443   59   1.2
8   341   0.91   27
54     1.09  
2    
 
  XDOMGeneratorListener       Line # 76 65 0% 58 12 90.5% 0.9047619
  XDOMGeneratorListener.MarkerBlock       Line # 82 0 0% 1 1 0% 0.0
 
  (988)
 
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.internal.parser;
21   
22    import java.util.ArrayList;
23    import java.util.Collections;
24    import java.util.List;
25    import java.util.Map;
26    import java.util.Stack;
27   
28    import org.xwiki.rendering.block.AbstractBlock;
29    import org.xwiki.rendering.block.Block;
30    import org.xwiki.rendering.block.BulletedListBlock;
31    import org.xwiki.rendering.block.DefinitionDescriptionBlock;
32    import org.xwiki.rendering.block.DefinitionListBlock;
33    import org.xwiki.rendering.block.DefinitionTermBlock;
34    import org.xwiki.rendering.block.EmptyLinesBlock;
35    import org.xwiki.rendering.block.FormatBlock;
36    import org.xwiki.rendering.block.GroupBlock;
37    import org.xwiki.rendering.block.HeaderBlock;
38    import org.xwiki.rendering.block.HorizontalLineBlock;
39    import org.xwiki.rendering.block.IdBlock;
40    import org.xwiki.rendering.block.ImageBlock;
41    import org.xwiki.rendering.block.LinkBlock;
42    import org.xwiki.rendering.block.ListItemBlock;
43    import org.xwiki.rendering.block.MacroBlock;
44    import org.xwiki.rendering.block.MacroMarkerBlock;
45    import org.xwiki.rendering.block.MetaDataBlock;
46    import org.xwiki.rendering.block.NewLineBlock;
47    import org.xwiki.rendering.block.NumberedListBlock;
48    import org.xwiki.rendering.block.ParagraphBlock;
49    import org.xwiki.rendering.block.QuotationBlock;
50    import org.xwiki.rendering.block.QuotationLineBlock;
51    import org.xwiki.rendering.block.RawBlock;
52    import org.xwiki.rendering.block.SectionBlock;
53    import org.xwiki.rendering.block.SpaceBlock;
54    import org.xwiki.rendering.block.SpecialSymbolBlock;
55    import org.xwiki.rendering.block.TableBlock;
56    import org.xwiki.rendering.block.TableCellBlock;
57    import org.xwiki.rendering.block.TableHeadCellBlock;
58    import org.xwiki.rendering.block.TableRowBlock;
59    import org.xwiki.rendering.block.VerbatimBlock;
60    import org.xwiki.rendering.block.WordBlock;
61    import org.xwiki.rendering.block.XDOM;
62    import org.xwiki.rendering.listener.Format;
63    import org.xwiki.rendering.listener.HeaderLevel;
64    import org.xwiki.rendering.listener.MetaData;
65    import org.xwiki.rendering.listener.reference.ResourceReference;
66    import org.xwiki.rendering.listener.ListType;
67    import org.xwiki.rendering.listener.Listener;
68    import org.xwiki.rendering.syntax.Syntax;
69   
70    /**
71    * Produce a {@link XDOM} based on events.
72    *
73    * @version $Id: a0f77bd05de45d78fc71ad7e38814eb516374d36 $
74    * @since 2.1M1
75    */
 
76    public class XDOMGeneratorListener implements Listener
77    {
78    private Stack<Block> stack = new Stack<Block>();
79   
80    private final MarkerBlock marker = new MarkerBlock();
81   
 
82    private static class MarkerBlock extends AbstractBlock
83    {
 
84  0 toggle @Override
85    public void traverse(Listener listener)
86    {
87    // Nothing to do since this block is only used as a marker.
88    }
89    }
90   
 
91  1084 toggle public XDOM getXDOM()
92    {
93  1084 List<Block> blocks = generateListFromStack();
94   
95    // support even events without begin/endDocument for partial content
96  1084 if (!blocks.isEmpty() && blocks.get(0) instanceof XDOM) {
97  1084 return (XDOM) blocks.get(0);
98    } else {
99  0 return new XDOM(blocks);
100    }
101    }
102   
 
103  5558 toggle private List<Block> generateListFromStack()
104    {
105  5558 List<Block> blocks = new ArrayList<Block>();
106  17612 while (!this.stack.empty()) {
107  16528 if (this.stack.peek() != this.marker) {
108  12054 blocks.add(this.stack.pop());
109    } else {
110  4474 this.stack.pop();
111  4474 break;
112    }
113    }
114  5558 Collections.reverse(blocks);
115  5558 return blocks;
116    }
117   
 
118  78 toggle @Override
119    public void beginDefinitionDescription()
120    {
121  78 this.stack.push(this.marker);
122    }
123   
 
124  85 toggle @Override
125    public void beginDefinitionList(Map<String, String> parameters)
126    {
127  85 this.stack.push(this.marker);
128    }
129   
 
130  62 toggle @Override
131    public void beginDefinitionTerm()
132    {
133  62 this.stack.push(this.marker);
134    }
135   
136    /**
137    * {@inheritDoc}
138    * @since 3.0M2
139    */
 
140  1084 toggle @Override
141    public void beginDocument(MetaData metaData)
142    {
143  1084 this.stack.push(this.marker);
144    }
145   
 
146  298 toggle @Override
147    public void beginFormat(Format format, Map<String, String> parameters)
148    {
149  298 this.stack.push(this.marker);
150    }
151   
 
152  84 toggle @Override
153    public void beginGroup(Map<String, String> parameters)
154    {
155  84 this.stack.push(this.marker);
156    }
157   
 
158  240 toggle @Override
159    public void beginHeader(HeaderLevel level, String id, Map<String, String> parameters)
160    {
161  240 this.stack.push(this.marker);
162    }
163   
 
164  208 toggle @Override
165    public void beginList(ListType listType, Map<String, String> parameters)
166    {
167  208 this.stack.push(this.marker);
168    }
169   
 
170  278 toggle @Override
171    public void beginListItem()
172    {
173  278 this.stack.push(this.marker);
174    }
175   
 
176  0 toggle @Override
177    public void beginMacroMarker(String name, Map<String, String> macroParameters, String content, boolean isInline)
178    {
179  0 this.stack.push(this.marker);
180    }
181   
 
182  955 toggle @Override
183    public void beginParagraph(Map<String, String> parameters)
184    {
185  955 this.stack.push(this.marker);
186    }
187   
 
188  34 toggle @Override
189    public void beginQuotation(Map<String, String> parameters)
190    {
191  34 this.stack.push(this.marker);
192    }
193   
 
194  57 toggle @Override
195    public void beginQuotationLine()
196    {
197  57 this.stack.push(this.marker);
198    }
199   
 
200  270 toggle @Override
201    public void beginSection(Map<String, String> parameters)
202    {
203  270 this.stack.push(this.marker);
204    }
205   
 
206  67 toggle @Override
207    public void beginTable(Map<String, String> parameters)
208    {
209  67 this.stack.push(this.marker);
210    }
211   
 
212  167 toggle @Override
213    public void beginTableCell(Map<String, String> parameters)
214    {
215  167 this.stack.push(this.marker);
216    }
217   
 
218  101 toggle @Override
219    public void beginTableHeadCell(Map<String, String> parameters)
220    {
221  101 this.stack.push(this.marker);
222    }
223   
 
224  127 toggle @Override
225    public void beginTableRow(Map<String, String> parameters)
226    {
227  127 this.stack.push(this.marker);
228    }
229   
 
230  279 toggle @Override
231    public void beginLink(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
232    {
233  279 this.stack.push(this.marker);
234    }
235   
236    /**
237    * {@inheritDoc}
238    * @since 3.0M2
239    */
 
240  0 toggle @Override
241    public void beginMetaData(MetaData metadata)
242    {
243  0 this.stack.push(this.marker);
244    }
245   
 
246  78 toggle @Override
247    public void endDefinitionDescription()
248    {
249  78 this.stack.push(new DefinitionDescriptionBlock(generateListFromStack()));
250    }
251   
 
252  85 toggle @Override
253    public void endDefinitionList(Map<String, String> parameters)
254    {
255  85 this.stack.push(new DefinitionListBlock(generateListFromStack(), parameters));
256    }
257   
 
258  62 toggle @Override
259    public void endDefinitionTerm()
260    {
261  62 this.stack.push(new DefinitionTermBlock(generateListFromStack()));
262    }
263   
264    /**
265    * {@inheritDoc}
266    * @since 3.0M2
267    */
 
268  1084 toggle @Override
269    public void endDocument(MetaData metaData)
270    {
271  1084 this.stack.push(new XDOM(generateListFromStack(), metaData));
272    }
273   
 
274  298 toggle @Override
275    public void endFormat(Format format, Map<String, String> parameters)
276    {
277  298 this.stack.push(new FormatBlock(generateListFromStack(), format, parameters));
278    }
279   
 
280  84 toggle @Override
281    public void endGroup(Map<String, String> parameters)
282    {
283  84 this.stack.push(new GroupBlock(generateListFromStack(), parameters));
284    }
285   
 
286  240 toggle @Override
287    public void endHeader(HeaderLevel level, String id, Map<String, String> parameters)
288    {
289  240 this.stack.push(new HeaderBlock(generateListFromStack(), level, parameters, id));
290    }
291   
 
292  208 toggle @Override
293    public void endList(ListType listType, Map<String, String> parameters)
294    {
295  208 if (listType == ListType.BULLETED) {
296  168 this.stack.push(new BulletedListBlock(generateListFromStack(), parameters));
297    } else {
298  40 this.stack.push(new NumberedListBlock(generateListFromStack(), parameters));
299    }
300    }
301   
 
302  278 toggle @Override
303    public void endListItem()
304    {
305  278 this.stack.push(new ListItemBlock(generateListFromStack()));
306    }
307   
 
308  0 toggle @Override
309    public void endMacroMarker(String name, Map<String, String> macroParameters, String content, boolean isInline)
310    {
311  0 this.stack.push(new MacroMarkerBlock(name, macroParameters, content, generateListFromStack(), isInline));
312    }
313   
 
314  955 toggle @Override
315    public void endParagraph(Map<String, String> parameters)
316    {
317  955 this.stack.push(new ParagraphBlock(generateListFromStack(), parameters));
318    }
319   
 
320  34 toggle @Override
321    public void endQuotation(Map<String, String> parameters)
322    {
323  34 this.stack.push(new QuotationBlock(generateListFromStack(), parameters));
324    }
325   
 
326  57 toggle @Override
327    public void endQuotationLine()
328    {
329  57 this.stack.push(new QuotationLineBlock(generateListFromStack()));
330    }
331   
 
332  270 toggle @Override
333    public void endSection(Map<String, String> parameters)
334    {
335  270 this.stack.push(new SectionBlock(generateListFromStack(), parameters));
336    }
337   
 
338  67 toggle @Override
339    public void endTable(Map<String, String> parameters)
340    {
341  67 this.stack.push(new TableBlock(generateListFromStack(), parameters));
342    }
343   
 
344  167 toggle @Override
345    public void endTableCell(Map<String, String> parameters)
346    {
347  167 this.stack.push(new TableCellBlock(generateListFromStack(), parameters));
348    }
349   
 
350  101 toggle @Override
351    public void endTableHeadCell(Map<String, String> parameters)
352    {
353  101 this.stack.push(new TableHeadCellBlock(generateListFromStack(), parameters));
354    }
355   
 
356  127 toggle @Override
357    public void endTableRow(Map<String, String> parameters)
358    {
359  127 this.stack.push(new TableRowBlock(generateListFromStack(), parameters));
360    }
361   
 
362  279 toggle @Override
363    public void endLink(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
364    {
365  279 this.stack.push(new LinkBlock(generateListFromStack(), reference, isFreeStandingURI, parameters));
366    }
367   
368    /**
369    * {@inheritDoc}
370    * @since 3.0M2
371    */
 
372  0 toggle @Override
373    public void endMetaData(MetaData metadata)
374    {
375  0 this.stack.push(new MetaDataBlock(generateListFromStack(), metadata));
376    }
377   
 
378  32 toggle @Override
379    public void onEmptyLines(int count)
380    {
381  32 this.stack.push(new EmptyLinesBlock(count));
382    }
383   
 
384  46 toggle @Override
385    public void onHorizontalLine(Map<String, String> parameters)
386    {
387  46 this.stack.push(new HorizontalLineBlock(parameters));
388    }
389   
 
390  6 toggle @Override
391    public void onId(String name)
392    {
393  6 this.stack.push(new IdBlock(name));
394    }
395   
 
396  309 toggle @Override
397    public void onMacro(String id, Map<String, String> macroParameters, String content, boolean isInline)
398    {
399  309 this.stack.push(new MacroBlock(id, macroParameters, content, isInline));
400    }
401   
 
402  339 toggle @Override
403    public void onNewLine()
404    {
405  339 this.stack.push(new NewLineBlock());
406    }
407   
 
408  0 toggle @Override
409    public void onRawText(String rawContent, Syntax syntax)
410    {
411  0 this.stack.push(new RawBlock(rawContent, syntax));
412    }
413   
 
414  1949 toggle @Override
415    public void onSpace()
416    {
417  1949 this.stack.push(new SpaceBlock());
418    }
419   
 
420  1064 toggle @Override
421    public void onSpecialSymbol(char symbol)
422    {
423  1064 this.stack.push(new SpecialSymbolBlock(symbol));
424    }
425   
 
426  61 toggle @Override
427    public void onVerbatim(String protectedString, boolean isInline, Map<String, String> parameters)
428    {
429  61 this.stack.push(new VerbatimBlock(protectedString, parameters, isInline));
430    }
431   
 
432  3667 toggle @Override
433    public void onWord(String word)
434    {
435  3667 this.stack.push(new WordBlock(word));
436    }
437   
 
438  107 toggle @Override
439    public void onImage(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
440    {
441  107 this.stack.push(new ImageBlock(reference, isFreeStandingURI, parameters));
442    }
443    }