1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.listener

File QueueListener.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

4
61
55
2
461
294
58
0.95
1.11
27.5
1.05

Classes

Class Line # Actions
QueueListener 35 59 0% 57 4
0.9658119796.6%
QueueListener.Event 47 2 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 484 tests. .

Source view

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: 5a16b167c58fce8e31505a8c5e33e8126d1b1a65 $
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: 5a16b167c58fce8e31505a8c5e33e8126d1b1a65 $
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  14842 toggle public Event(EventType eventType, Object[] eventParameters)
64    {
65  14842 this.eventType = eventType;
66  14842 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  324 toggle public Event getEvent(int depth)
77    {
78  324 Event event = null;
79   
80  324 if (depth > 0 && size() > depth - 1) {
81  320 event = get(depth - 1);
82    }
83   
84  324 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  1070 toggle public void consumeEvents(Listener listener)
93    {
94  6318 while (!isEmpty()) {
95  5248 Event event = remove();
96  5248 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  14842 toggle private void saveEvent(EventType eventType, Object... objects)
107    {
108  14842 offer(new Event(eventType, objects));
109    }
110   
 
111  21 toggle @Override
112    public void beginDefinitionDescription()
113    {
114  21 saveEvent(EventType.BEGIN_DEFINITION_DESCRIPTION);
115    }
116   
117    /**
118    * {@inheritDoc}
119    *
120    * @since 2.0RC1
121    */
 
122  22 toggle @Override
123    public void beginDefinitionList(Map<String, String> parameters)
124    {
125  22 saveEvent(EventType.BEGIN_DEFINITION_LIST, parameters);
126    }
127   
 
128  17 toggle @Override
129    public void beginDefinitionTerm()
130    {
131  17 saveEvent(EventType.BEGIN_DEFINITION_TERM);
132    }
133   
134    /**
135    * {@inheritDoc}
136    *
137    * @since 3.0M2
138    */
 
139  429 toggle @Override
140    public void beginDocument(MetaData metadata)
141    {
142  429 saveEvent(EventType.BEGIN_DOCUMENT, metadata);
143    }
144   
 
145  29 toggle @Override
146    public void beginGroup(Map<String, String> parameters)
147    {
148  29 saveEvent(EventType.BEGIN_GROUP, parameters);
149    }
150   
 
151  184 toggle @Override
152    public void beginFormat(Format format, Map<String, String> parameters)
153    {
154  184 saveEvent(EventType.BEGIN_FORMAT, format, parameters);
155    }
156   
 
157  60 toggle @Override
158    public void beginHeader(HeaderLevel level, String id, Map<String, String> parameters)
159    {
160  60 saveEvent(EventType.BEGIN_HEADER, level, id, parameters);
161    }
162   
163    /**
164    * {@inheritDoc}
165    *
166    * @since 2.5RC1
167    */
 
168  178 toggle @Override
169    public void beginLink(ResourceReference reference, boolean freestanding, Map<String, String> parameters)
170    {
171  178 saveEvent(EventType.BEGIN_LINK, reference, freestanding, parameters);
172    }
173   
 
174  64 toggle @Override
175    public void beginList(ListType type, Map<String, String> parameters)
176    {
177  64 saveEvent(EventType.BEGIN_LIST, type, parameters);
178    }
179   
 
180  94 toggle @Override
181    public void beginListItem()
182    {
183  94 saveEvent(EventType.BEGIN_LIST_ITEM);
184    }
185   
 
186  47 toggle @Override
187    public void beginMacroMarker(String name, Map<String, String> parameters, String content, boolean isInline)
188    {
189  47 saveEvent(EventType.BEGIN_MACRO_MARKER, name, parameters, content, isInline);
190    }
191   
 
192  424 toggle @Override
193    public void beginParagraph(Map<String, String> parameters)
194    {
195  424 saveEvent(EventType.BEGIN_PARAGRAPH, parameters);
196    }
197   
 
198  11 toggle @Override
199    public void beginQuotation(Map<String, String> parameters)
200    {
201  11 saveEvent(EventType.BEGIN_QUOTATION, parameters);
202    }
203   
 
204  17 toggle @Override
205    public void beginQuotationLine()
206    {
207  17 saveEvent(EventType.BEGIN_QUOTATION_LINE);
208    }
209   
 
210  65 toggle @Override
211    public void beginSection(Map<String, String> parameters)
212    {
213  65 saveEvent(EventType.BEGIN_SECTION, parameters);
214    }
215   
 
216  26 toggle @Override
217    public void beginTable(Map<String, String> parameters)
218    {
219  26 saveEvent(EventType.BEGIN_TABLE, parameters);
220    }
221   
 
222  72 toggle @Override
223    public void beginTableCell(Map<String, String> parameters)
224    {
225  72 saveEvent(EventType.BEGIN_TABLE_CELL, parameters);
226    }
227   
 
228  39 toggle @Override
229    public void beginTableHeadCell(Map<String, String> parameters)
230    {
231  39 saveEvent(EventType.BEGIN_TABLE_HEAD_CELL, parameters);
232    }
233   
 
234  55 toggle @Override
235    public void beginTableRow(Map<String, String> parameters)
236    {
237  55 saveEvent(EventType.BEGIN_TABLE_ROW, parameters);
238    }
239   
240    /**
241    * {@inheritDoc}
242    *
243    * @since 3.0M2
244    */
 
245  0 toggle @Override
246    public void beginMetaData(MetaData metadata)
247    {
248  0 saveEvent(EventType.BEGIN_METADATA, metadata);
249    }
250   
 
251  21 toggle @Override
252    public void endDefinitionDescription()
253    {
254  21 saveEvent(EventType.END_DEFINITION_DESCRIPTION);
255    }
256   
257    /**
258    * {@inheritDoc}
259    *
260    * @since 2.0RC1
261    */
 
262  22 toggle @Override
263    public void endDefinitionList(Map<String, String> parameters)
264    {
265  22 saveEvent(EventType.END_DEFINITION_LIST, parameters);
266    }
267   
 
268  17 toggle @Override
269    public void endDefinitionTerm()
270    {
271  17 saveEvent(EventType.END_DEFINITION_TERM);
272    }
273   
274    /**
275    * {@inheritDoc}
276    *
277    * @since 3.0M2
278    */
 
279  644 toggle @Override
280    public void endDocument(MetaData metadata)
281    {
282  644 saveEvent(EventType.END_DOCUMENT, metadata);
283    }
284   
 
285  29 toggle @Override
286    public void endGroup(Map<String, String> parameters)
287    {
288  29 saveEvent(EventType.END_GROUP, parameters);
289    }
290   
 
291  184 toggle @Override
292    public void endFormat(Format format, Map<String, String> parameters)
293    {
294  184 saveEvent(EventType.END_FORMAT, format, parameters);
295    }
296   
 
297  60 toggle @Override
298    public void endHeader(HeaderLevel level, String id, Map<String, String> parameters)
299    {
300  60 saveEvent(EventType.END_HEADER, level, id, parameters);
301    }
302   
303    /**
304    * {@inheritDoc}
305    *
306    * @since 2.5RC1
307    */
 
308  178 toggle @Override
309    public void endLink(ResourceReference reference, boolean freestanding, Map<String, String> parameters)
310    {
311  178 saveEvent(EventType.END_LINK, reference, freestanding, parameters);
312    }
313   
 
314  64 toggle @Override
315    public void endList(ListType type, Map<String, String> parameters)
316    {
317  64 saveEvent(EventType.END_LIST, type, parameters);
318    }
319   
 
320  94 toggle @Override
321    public void endListItem()
322    {
323  94 saveEvent(EventType.END_LIST_ITEM);
324    }
325   
 
326  47 toggle @Override
327    public void endMacroMarker(String name, Map<String, String> parameters, String content, boolean isInline)
328    {
329  47 saveEvent(EventType.END_MACRO_MARKER, name, parameters, content, isInline);
330    }
331   
 
332  421 toggle @Override
333    public void endParagraph(Map<String, String> parameters)
334    {
335  421 saveEvent(EventType.END_PARAGRAPH, parameters);
336    }
337   
 
338  11 toggle @Override
339    public void endQuotation(Map<String, String> parameters)
340    {
341  11 saveEvent(EventType.END_QUOTATION, parameters);
342    }
343   
 
344  17 toggle @Override
345    public void endQuotationLine()
346    {
347  17 saveEvent(EventType.END_QUOTATION_LINE);
348    }
349   
 
350  65 toggle @Override
351    public void endSection(Map<String, String> parameters)
352    {
353  65 saveEvent(EventType.END_SECTION, parameters);
354    }
355   
 
356  26 toggle @Override
357    public void endTable(Map<String, String> parameters)
358    {
359  26 saveEvent(EventType.END_TABLE, parameters);
360    }
361   
 
362  72 toggle @Override
363    public void endTableCell(Map<String, String> parameters)
364    {
365  72 saveEvent(EventType.END_TABLE_CELL, parameters);
366    }
367   
 
368  39 toggle @Override
369    public void endTableHeadCell(Map<String, String> parameters)
370    {
371  39 saveEvent(EventType.END_TABLE_HEAD_CELL, parameters);
372