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
61   452   58   1.11
4   294   0.95   27.5
55     1.05  
2    
 
  QueueListener       Line # 35 59 0% 57 4 96.6% 0.96581197
  QueueListener.Event       Line # 47 2 0% 1 0 100% 1.0
 
  (389)
 
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;
21   
22    import java.util.LinkedList;
23    import java.util.Map;
24   
25    import org.xwiki.rendering.listener.chaining.EventType;
26    import org.xwiki.rendering.listener.reference.ResourceReference;
27    import org.xwiki.rendering.syntax.Syntax;
28   
29    /**
30    * Manage a {@link java.util.Queue} of events.
31    *
32    * @version $Id: ce53436b9dcf3abaab09c1dc1d1c7445b2271bee $
33    * @since 2.1M1
34    */
 
35    public class QueueListener extends LinkedList<QueueListener.Event> implements Listener
36    {
37    /**
38    * Class ID for serialization.
39    */
40    private static final long serialVersionUID = 2869508092440006345L;
41   
42    /**
43    * An event.
44    *
45    * @version $Id: ce53436b9dcf3abaab09c1dc1d1c7445b2271bee $
46    */
 
47    public class Event
48    {
49    /**
50    * The type of the event.
51    */
52    public EventType eventType;
53   
54    /**
55    * The parameters of the event.
56    */
57    public Object[] eventParameters;
58   
59    /**
60    * @param eventType the type of the event
61    * @param eventParameters the parameters of the event
62    */
 
63  5791 toggle public Event(EventType eventType, Object[] eventParameters)
64    {
65  5791 this.eventType = eventType;
66  5791 this.eventParameters = eventParameters;
67    }
68    }
69   
70    /**
71    * Returns the event at the specified position in this queue.
72    *
73    * @param depth index of event to return.
74    * @return the evnet at the specified position in this queue.
75    */
 
76  286 toggle public Event getEvent(int depth)
77    {
78  286 Event event = null;
79   
80  286 if (depth > 0 && size() > depth - 1) {
81  282 event = get(depth - 1);
82    }
83   
84  286 return event;
85    }
86   
87    /**
88    * Send all stored events to provided {@link Listener}.
89    *
90    * @param listener the {@link Listener} on which to send events
91    */
 
92  228 toggle public void consumeEvents(Listener listener)
93    {
94  1141 while (!isEmpty()) {
95  913 Event event = remove();
96  913 event.eventType.fireEvent(listener, event.eventParameters);
97    }
98    }
99   
100    /**
101    * Store provided event.
102    *
103    * @param eventType the type of the event
104    * @param objects the parameters of the event
105    */
 
106  5791 toggle private void saveEvent(EventType eventType, Object... objects)
107    {
108  5791 offer(new Event(eventType, objects));
109    }
110   
 
111  18 toggle @Override
112    public void beginDefinitionDescription()
113    {
114  18 saveEvent(EventType.BEGIN_DEFINITION_DESCRIPTION);
115    }
116   
117    /**
118    * {@inheritDoc}
119    * @since 2.0RC1
120    */
 
121  20 toggle @Override
122    public void beginDefinitionList(Map<String, String> parameters)
123    {
124  20 saveEvent(EventType.BEGIN_DEFINITION_LIST, parameters);
125    }
126   
 
127  14 toggle @Override
128    public void beginDefinitionTerm()
129    {
130  14 saveEvent(EventType.BEGIN_DEFINITION_TERM);
131    }
132   
133    /**
134    * {@inheritDoc}
135    * @since 3.0M2
136    */
 
137  399 toggle @Override
138    public void beginDocument(MetaData metaData)
139    {
140  399 saveEvent(EventType.BEGIN_DOCUMENT, metaData);
141    }
142   
 
143  33 toggle @Override
144    public void beginGroup(Map<String, String> parameters)
145    {
146  33 saveEvent(EventType.BEGIN_GROUP, parameters);
147    }
148   
 
149  88 toggle @Override
150    public void beginFormat(Format format, Map<String, String> parameters)
151    {
152  88 saveEvent(EventType.BEGIN_FORMAT, format, parameters);
153    }
154   
 
155  50 toggle @Override
156    public void beginHeader(HeaderLevel level, String id, Map<String, String> parameters)
157    {
158  50 saveEvent(EventType.BEGIN_HEADER, level, id, parameters);
159    }
160   
161    /**
162    * {@inheritDoc}
163    * @since 2.5RC1
164    */
 
165  79 toggle @Override
166    public void beginLink(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
167    {
168  79 saveEvent(EventType.BEGIN_LINK, reference, isFreeStandingURI, parameters);
169    }
170   
 
171  66 toggle @Override
172    public void beginList(ListType listType, Map<String, String> parameters)
173    {
174  66 saveEvent(EventType.BEGIN_LIST, listType, parameters);
175    }
176   
 
177  76 toggle @Override
178    public void beginListItem()
179    {
180  76 saveEvent(EventType.BEGIN_LIST_ITEM);
181    }
182   
 
183  24 toggle @Override
184    public void beginMacroMarker(String name, Map<String, String> parameters, String content, boolean isInline)
185    {
186  24 saveEvent(EventType.BEGIN_MACRO_MARKER, name, parameters, content, isInline);
187    }
188   
 
189  285 toggle @Override
190    public void beginParagraph(Map<String, String> parameters)
191    {
192  285 saveEvent(EventType.BEGIN_PARAGRAPH, parameters);
193    }
194   
 
195  9 toggle @Override
196    public void beginQuotation(Map<String, String> parameters)
197    {
198  9 saveEvent(EventType.BEGIN_QUOTATION, parameters);
199    }
200   
 
201  16 toggle @Override
202    public void beginQuotationLine()
203    {
204  16 saveEvent(EventType.BEGIN_QUOTATION_LINE);
205    }
206   
 
207  55 toggle @Override
208    public void beginSection(Map<String, String> parameters)
209    {
210  55 saveEvent(EventType.BEGIN_SECTION, parameters);
211    }
212   
 
213  21 toggle @Override
214    public void beginTable(Map<String, String> parameters)
215    {
216  21 saveEvent(EventType.BEGIN_TABLE, parameters);
217    }
218   
 
219  53 toggle @Override
220    public void beginTableCell(Map<String, String> parameters)
221    {
222  53 saveEvent(EventType.BEGIN_TABLE_CELL, parameters);
223    }
224   
 
225  31 toggle @Override
226    public void beginTableHeadCell(Map<String, String> parameters)
227    {
228  31 saveEvent(EventType.BEGIN_TABLE_HEAD_CELL, parameters);
229    }
230   
 
231  39 toggle @Override
232    public void beginTableRow(Map<String, String> parameters)
233    {
234  39 saveEvent(EventType.BEGIN_TABLE_ROW, parameters);
235    }
236   
237    /**
238    * {@inheritDoc}
239    * @since 3.0M2
240    */
 
241  0 toggle @Override
242    public void beginMetaData(MetaData metadata)
243    {
244  0 saveEvent(EventType.BEGIN_METADATA, metadata);
245    }
246   
 
247  18 toggle @Override
248    public void endDefinitionDescription()
249    {
250  18 saveEvent(EventType.END_DEFINITION_DESCRIPTION);
251    }
252   
253    /**
254    * {@inheritDoc}
255    * @since 2.0RC1
256    */
 
257  20 toggle @Override
258    public void endDefinitionList(Map<String, String> parameters)
259    {
260  20 saveEvent(EventType.END_DEFINITION_LIST, parameters);
261    }
262   
 
263  14 toggle @Override
264    public void endDefinitionTerm()
265    {
266  14 saveEvent(EventType.END_DEFINITION_TERM);
267    }
268   
269    /**
270    * {@inheritDoc}
271    * @since 3.0M2
272    */
 
273  399 toggle @Override
274    public void endDocument(MetaData metaData)
275    {
276  399 saveEvent(EventType.END_DOCUMENT, metaData);
277    }
278   
 
279  33 toggle @Override
280    public void endGroup(Map<String, String> parameters)
281    {
282  33 saveEvent(EventType.END_GROUP, parameters);
283    }
284   
 
285  88 toggle @Override
286    public void endFormat(Format format, Map<String, String> parameters)
287    {
288  88 saveEvent(EventType.END_FORMAT, format, parameters);
289    }
290   
 
291  50 toggle @Override
292    public void endHeader(HeaderLevel level, String id, Map<String, String> parameters)
293    {
294  50 saveEvent(EventType.END_HEADER, level, id, parameters);
295    }
296   
297    /**
298    * {@inheritDoc}
299    * @since 2.5RC1
300    */
 
301  79 toggle @Override
302    public void endLink(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
303    {
304  79 saveEvent(EventType.END_LINK, reference, isFreeStandingURI, parameters);
305    }
306   
 
307  66 toggle @Override
308    public void endList(ListType listType, Map<String, String> parameters)
309    {
310  66 saveEvent(EventType.END_LIST, listType, parameters);
311    }
312   
 
313  76 toggle @Override
314    public void endListItem()
315    {
316  76 saveEvent(EventType.END_LIST_ITEM);
317    }
318   
 
319  24 toggle @Override
320    public void endMacroMarker(String name, Map<String, String> parameters, String content, boolean isInline)
321    {
322  24 saveEvent(EventType.END_MACRO_MARKER, name, parameters, content, isInline);
323    }
324   
 
325  284 toggle @Override
326    public void endParagraph(Map<String, String> parameters)
327    {
328  284 saveEvent(EventType.END_PARAGRAPH, parameters);
329    }
330   
 
331  9 toggle @Override
332    public void endQuotation(Map<String, String> parameters)
333    {
334  9 saveEvent(EventType.END_QUOTATION, parameters);
335    }
336   
 
337  16 toggle @Override
338    public void endQuotationLine()
339    {
340  16 saveEvent(EventType.END_QUOTATION_LINE);
341    }
342   
 
343  55 toggle @Override
344    public void endSection(Map<String, String> parameters)
345    {
346  55 saveEvent(EventType.END_SECTION, parameters);
347    }
348   
 
349  21 toggle @Override
350    public void endTable(Map<String, String> parameters)
351    {
352  21 saveEvent(EventType.END_TABLE, parameters);
353    }
354   
 
355  53 toggle @Override
356    public void endTableCell(Map<String, String> parameters)
357    {
358  53 saveEvent(EventType.END_TABLE_CELL, parameters);
359    }
360   
 
361  31 toggle @Override
362    public void endTableHeadCell(Map<String, String> parameters)
363    {
364  31 saveEvent(EventType.END_TABLE_HEAD_CELL, parameters);
365    }
366   
 
367  39 toggle @Override
368    public void endTableRow(Map<String, String> parameters)
369    {
370  39 saveEvent(EventType.END_TABLE_ROW, parameters);
371    }
372   
373    /**
374    * {@inheritDoc}
375    * @since 3.0M2
376    */
 
377  0 toggle @Override
378    public void endMetaData(MetaData metadata)
379    {
380  0 saveEvent(EventType.END_METADATA, metadata);
381    }
382   
 
383  5 toggle @Override
384    public void onRawText(String text, Syntax syntax)
385    {
386  5 saveEvent(EventType.ON_RAW_TEXT, text, syntax);
387    }
388   
 
389  8 toggle @Override
390    public void onEmptyLines(int count)
391    {
392  8 saveEvent(EventType.ON_EMPTY_LINES, count);
393    }
394   
 
395  13 toggle @Override
396    public void onHorizontalLine(Map<String, String> parameters)
397    {
398  13 saveEvent(EventType.ON_HORIZONTAL_LINE, parameters);
399    }
400   
 
401  6 toggle @Override
402    public void onId(String name)
403    {
404  6 saveEvent(EventType.ON_ID, name);
405    }
406   
407    /**
408    * {@inheritDoc}
409    * @since 2.5RC1
410    */
 
411  39 toggle @Override
412    public void onImage(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
413    {
414  39 saveEvent(EventType.ON_IMAGE, reference, isFreeStandingURI, parameters);
415    }
416   
 
417  113 toggle @Override
418    public void onMacro(String id, Map<String, String> parameters, String content, boolean isInline)
419    {
420  113 saveEvent(EventType.ON_MACRO, id, parameters, content, isInline);
421    }
422   
 
423  109 toggle @Override
424    public void onNewLine()
425    {
426  109 saveEvent(EventType.ON_NEW_LINE);
427    }
428   
 
429  846 toggle @Override
430    public void onSpace()
431    {
432  846 saveEvent(EventType.ON_SPACE);
433    }
434   
 
435  326 toggle @Override
436    public void onSpecialSymbol(char symbol)
437    {
438  326 saveEvent(EventType.ON_SPECIAL_SYMBOL, symbol);
439    }
440   
 
441  20 toggle @Override
442    public void onVerbatim(String protectedString, boolean isInline, Map<String, String> parameters)
443    {
444  20 saveEvent(EventType.ON_VERBATIM, protectedString, isInline, parameters);
445    }
446   
 
447  1555 toggle @Override
448    public void onWord(String word)
449    {
450  1555 saveEvent(EventType.ON_WORD, word);
451    }
452    }