Clover Coverage Report - XWiki Rendering - Parent POM 4.0-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Mar 12 2012 18:03:13 CET
../../../../../../img/srcFileCovDistChart4.png 86% of files have more coverage
75   512   65   1.44
10   303   0.87   52
52     1.25  
1    
 
  DoxiaGeneratorListener       Line # 38 75 0% 65 82 40.1% 0.40145984
 
  (10)
 
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.doxia;
21   
22    import java.util.Map;
23   
24    import org.apache.maven.doxia.sink.Sink;
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.listener.Listener;
31    import org.xwiki.rendering.syntax.Syntax;
32   
33    /**
34    * Bridge XWiki Rendering Events to Doxia Events. This allows rendering an XDOM using a Doxia Sink.
35    *
36    * @version $Id: 0e26c7ef11b355d2016db19cc264fffe5b0ddc32 $
37    */
 
38    public class DoxiaGeneratorListener implements Listener
39    {
40    /**
41    * The Doxia Renderer to which to emit events to.
42    */
43    private Sink sink;
44   
45    /**
46    * Since we need to tell Doxia the section level and since XWiki Events only give the level for begin/endHeader
47    * events, we need to remember the header level in order to be able to properly close the section by sending
48    * the correct Doxia event.
49    */
50    private HeaderLevel headerLevel;
51   
52    /**
53    * @param sink the Doxia Renderer to which to emit events to
54    */
 
55  10 toggle public DoxiaGeneratorListener(Sink sink)
56    {
57  10 this.sink = sink;
58    }
59   
60    /**
61    * {@inheritDoc}
62    * @since 3.0M2
63    */
 
64  10 toggle @Override
65    public void beginDocument(MetaData metaData)
66    {
67  10 this.sink.head();
68  10 this.sink.head_();
69  10 this.sink.body();
70    }
71   
72    /**
73    * {@inheritDoc}
74    * @since 3.0M2
75    */
 
76  10 toggle @Override
77    public void endDocument(MetaData metaData)
78    {
79  10 this.sink.body_();
80    }
81   
 
82  0 toggle @Override
83    public void beginGroup(Map<String, String> parameters)
84    {
85    // Do nothing since Doxia doesn't support groups
86    }
87   
 
88  0 toggle @Override
89    public void endGroup(Map<String, String> parameters)
90    {
91    // Do nothing since Doxia doesn't support groups
92    }
93   
 
94  1 toggle @Override
95    public void onVerbatim(String protectedString, boolean isInline, Map<String, String> parameters)
96    {
97    // TODO: Handle parameters
98  1 this.sink.verbatim(false);
99  1 this.sink.text(protectedString);
100  1 this.sink.verbatim_();
101    }
102   
 
103  8 toggle @Override
104    public void beginFormat(Format format, Map<String, String> parameters)
105    {
106    // TODO: Handle parameters
107  8 switch (format) {
108  7 case BOLD:
109  7 this.sink.bold();
110  7 break;
111  1 case ITALIC:
112  1 this.sink.italic();
113  1 break;
114  0 case STRIKEDOUT:
115    // TODO: Implement when we move to Doxia 1.0 beta 1.
116    // See http://jira.codehaus.org/browse/DOXIA-204
117  0 break;
118  0 case UNDERLINED:
119    // TODO: Implement when we move to Doxia 1.0 beta 1.
120    // See http://jira.codehaus.org/browse/DOXIA-204
121  0 break;
122  0 default:
123    // Unhandled format, don't do anything.
124    }
125    }
126   
 
127  8 toggle @Override
128    public void endFormat(Format format, Map<String, String> parameters)
129    {
130    // TODO: Handle parameters
131  8 switch (format) {
132  7 case BOLD:
133  7 this.sink.bold_();
134  7 break;
135  1 case ITALIC:
136  1 this.sink.italic_();
137  1 break;
138  0 case STRIKEDOUT:
139    // TODO: Implement when we move to Doxia 1.0 beta 1.
140    // See http://jira.codehaus.org/browse/DOXIA-204
141  0 break;
142  0 case UNDERLINED:
143    // TODO: Implement when we move to Doxia 1.0 beta 1.
144    // See http://jira.codehaus.org/browse/DOXIA-204
145  0 break;
146  0 default:
147    // Unhandled format, don't do anything.
148    }
149    }
150   
 
151  0 toggle @Override
152    public void beginList(ListType listType, Map<String, String> parameters)
153    {
154  0 if (listType == ListType.BULLETED) {
155  0 this.sink.list();
156    } else {
157    // TODO: Handle other numerotations (Roman, etc)
158  0 this.sink.numberedList(Sink.NUMBERING_DECIMAL);
159    }
160    }
161   
 
162  0 toggle @Override
163    public void beginListItem()
164    {
165  0 this.sink.listItem();
166    }
167   
 
168  0 toggle @Override
169    public void beginMacroMarker(String name, Map<String, String> parameters, String content, boolean isInline)
170    {
171    // Don't do anything since Doxia doesn't have macro markers and anyway we shouldn't
172    // do anything.
173    }
174   
 
175  9 toggle @Override
176    public void beginParagraph(Map<String, String> parameters)
177    {
178  9 this.sink.paragraph();
179    }
180   
 
181  6 toggle @Override
182    public void beginSection(Map<String, String> parameters)
183    {
184    // Note: The logic is in beginHeader.
185    }
186   
 
187  6 toggle @Override
188    public void beginHeader(HeaderLevel level, String id, Map<String, String> parameters)
189    {
190    // Doxia has only 5 section levels!
191  6 int levelAsInt = (level.getAsInt() < 6) ? level.getAsInt() : 5;
192  6 this.sink.section(levelAsInt, null);
193  6 this.sink.sectionTitle(levelAsInt, null);
194   
195    // Remember the header level for endSection() handling.
196  6 this.headerLevel = level;
197    }
198   
 
199  0 toggle @Override
200    public void endList(ListType listType, Map<String, String> parameters)
201    {
202  0 if (listType == ListType.BULLETED) {
203  0 this.sink.list_();
204    } else {
205  0 this.sink.numberedList_();
206    }
207    }
208   
 
209  0 toggle @Override
210    public void endListItem()
211    {
212  0 this.sink.listItem_();
213    }
214   
 
215  0 toggle @Override
216    public void endMacroMarker(String name, Map<String, String> parameters, String content, boolean isInline)
217    {
218    // Don't do anything since Doxia doesn't have macro markers and anyway we shouldn't
219    // do anything.
220    }
221   
 
222  9 toggle @Override
223    public void endParagraph(Map<String, String> parameters)
224    {
225  9 this.sink.paragraph_();
226    }
227   
 
228  6 toggle @Override
229    public void endSection(Map<String, String> parameters)
230    {
231    // Doxia has only 5 section levels!
232  6 int levelAsInt = (this.headerLevel.getAsInt() < 6) ? this.headerLevel.getAsInt() : 5;
233  6 this.sink.section_(levelAsInt);
234    }
235   
 
236  6 toggle @Override
237    public void endHeader(HeaderLevel level, String id, Map<String, String> parameters)
238    {
239    // Doxia has only 5 section levels!
240  6 int levelAsInt = (level.getAsInt() < 6) ? level.getAsInt() : 5;
241  6 this.sink.sectionTitle_(levelAsInt);
242    }
243   
 
244  0 toggle @Override
245    public void onMacro(String id, Map<String, String> parameters, String content, boolean isInline)
246    {
247    // Don't do anything since macros have already been transformed so this method
248    // should not be called.
249    }
250   
 
251  0 toggle @Override
252    public void onNewLine()
253    {
254    // TODO: Decide when to generate a line break and when to generate a new line
255   
256    // Since there's no On NewLine event in Doxia we simply generate text
257  0 this.sink.text("\n");
258    }
259   
 
260  48 toggle @Override
261    public void onSpace()
262    {
263    // Since there's no On Space event in Doxia we simply generate text
264  48 this.sink.text(" ");
265    }
266   
 
267  5 toggle @Override
268    public void onSpecialSymbol(char symbol)
269    {
270    // Since there's no On Special Symbol event in Doxia we simply generate text
271  5 this.sink.text("" + symbol);
272    }
273   
 
274  56 toggle @Override
275    public void onWord(String word)
276    {
277  56 this.sink.text(word);
278    }
279   
 
280  0 toggle @Override
281    public void onId(String name)
282    {
283    // TODO: Find out what to do...
284    }
285   
 
286  0 toggle @Override
287    public void onRawText(String text, Syntax syntax)
288    {
289    // TODO: Ensure this is correct. The problem is that Doxia doesn't seem to have a syntax
290    // associated with the raw text so I'm not sure how the renderers (sink in Doxia language)
291    // can decide whether to print it or not.
292  0 this.sink.rawText(text);
293    }
294   
 
295  0 toggle @Override
296    public void onHorizontalLine(Map<String, String> parameters)
297    {
298    // TODO: Handle parameters
299  0 this.sink.horizontalRule();
300    }
301   
 
302  0 toggle @Override
303    public void onEmptyLines(int count)
304    {
305    // TODO: Find what to do...
306    }
307   
308    /**
309    * {@inheritDoc}
310    * @since 2.0RC1
311    */
 
312  0 toggle @Override
313    public void beginDefinitionList(Map<String, String> parameters)
314    {
315    // TODO: Handle parameters
316  0 this.sink.definitionList();
317    }
318   
319    /**
320    * {@inheritDoc}
321    * @since 2.0RC1
322    */
 
323  0 toggle @Override
324    public void endDefinitionList(Map<String, String> parameters)
325    {
326    // TODO: Handle parameters
327  0 this.sink.definitionList_();
328    }
329   
330    /**
331    * {@inheritDoc}
332    * @since 1.6M2
333    */
 
334  0 toggle @Override
335    public void beginDefinitionTerm()
336    {
337  0 this.sink.definedTerm();
338    }
339   
340    /**
341    * {@inheritDoc}
342    * @since 1.6M2
343    */
 
344  0 toggle @Override
345    public void beginDefinitionDescription()
346    {
347  0 this.sink.definition();
348    }
349   
350    /**
351    * {@inheritDoc}
352    * @since 1.6M2
353    */
 
354  0 toggle @Override
355    public void endDefinitionTerm()
356    {
357  0 this.sink.definedTerm_();
358    }
359   
360    /**
361    * {@inheritDoc}
362    * @since 1.6M2
363    */
 
364  0 toggle @Override
365    public void endDefinitionDescription()
366    {
367  0 this.sink.definition_();
368    }
369   
370    /**
371    * {@inheritDoc}
372    * @since 1.6M2
373    */
 
374  0 toggle @Override
375    public void beginQuotation(Map<String, String> parameters)
376    {
377    // TODO: Doxia doesn't seem to have support for quotation... Find out what to do...
378    }
379   
380    /**
381    * {@inheritDoc}
382    * @since 1.6M2
383    */
 
384  0 toggle @Override
385    public void endQuotation(Map<String, String> parameters)
386    {
387    // TODO: Doxia doesn't seem to have support for quotation... Find out what to do...
388    }
389   
390    /**
391    * {@inheritDoc}
392    * @since 1.6M2
393    */
 
394  0 toggle @Override
395    public void beginQuotationLine()
396    {
397    // TODO: Doxia doesn't seem to have support for quotation... Find out what to do...
398    }
399   
400    /**
401    * {@inheritDoc}
402    * @since 1.6M2
403    */
 
404  0 toggle @Override
405    public void endQuotationLine()
406    {
407    // TODO: Doxia doesn't seem to have support for quotation... Find out what to do...
408    }
409   
 
410  0 toggle @Override
411    public void beginTable(Map<String, String> parameters)
412    {
413  0 this.sink.table();
414    }
415   
 
416  0 toggle @Override
417    public void beginTableCell(Map<String, String> parameters)
418    {
419  0 this.sink.tableCell();
420    }
421   
 
422  0 toggle @Override
423    public void beginTableHeadCell(Map<String, String> parameters)
424    {
425  0 this.sink.tableHeaderCell();
426    }
427   
 
428  0 toggle @Override
429    public void beginTableRow(Map<String, String> parameters)
430    {
431  0 this.sink.tableRow();
432    }
433   
 
434  0 toggle @Override
435    public void endTable(Map<String, String> parameters)
436    {
437  0 this.sink.table_();
438    }
439   
 
440  0 toggle @Override
441    public void endTableCell(Map<String, String> parameters)
442    {
443  0 this.sink.tableCell_();
444    }
445   
 
446  0 toggle @Override
447    public void endTableHeadCell(Map<String, String> parameters)
448    {
449  0 this.sink.tableHeaderCell_();
450    }
451   
 
452  0 toggle @Override
453    public void endTableRow(Map<String, String> parameters)
454    {
455  0 this.sink.tableRow_();
456    }
457   
458    /**
459    * {@inheritDoc}
460    * @since 2.5RC1
461    */
 
462  0 toggle @Override
463    public void beginLink(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
464    {
465  0 this.sink.link(reference.getReference());
466    }
467   
468    /**
469    * {@inheritDoc}
470    * @since 2.5RC1
471    */
 
472  0 toggle @Override
473    public void endLink(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
474    {
475  0 this.sink.link_();
476    }
477   
478    /**
479    * {@inheritDoc}
480    * @since 2.5RC1
481    */
 
482  0 toggle @Override
483    public void onImage(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
484    {
485  0 this.sink.figure();
486    // TODO: handle special XWiki format for image locations. How do we pass image bits to Doxia?
487    // TODO: Handle parameters
488    // TODO: Handle free standing URI (if supported by Doxia)
489  0 this.sink.figureGraphics(reference.getReference());
490  0 this.sink.figure_();
491    }
492   
493    /**
494    * {@inheritDoc}
495    * @since 3.0M2
496    */
 
497  0 toggle @Override
498    public void beginMetaData(MetaData metadata)
499    {
500    // Doxia doesn't support the notion of metadata
501    }
502   
503    /**
504    * {@inheritDoc}
505    * @since 3.0M2
506    */
 
507  0 toggle @Override
508    public void endMetaData(MetaData metadata)
509    {
510    // Doxia doesn't support the notion of metadata
511    }
512    }