1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.rendering.listener

File QueueListener.java

 

Coverage histogram

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

Code metrics

4
63
57
2
473
304
60
0.95
1.11
28.5
1.05

Classes

Class Line # Actions
QueueListener 35 61 0% 59 2
0.983471198.3%
QueueListener.Event 47 2 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 499 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: db772e294a4fcb1001b4991864ab68dcd3d92ae7 $
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: db772e294a4fcb1001b4991864ab68dcd3d92ae7 $
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  61953 toggle public Event(EventType eventType, Object... eventParameters)
64    {
65  61969 this.eventType = eventType;
66  61966 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  321 toggle public Event getEvent(int depth)
77    {
78  321 Event event = null;
79   
80  321 if (depth > 0 && size() > depth - 1) {
81  317 event = get(depth - 1);
82    }
83   
84  321 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  14939 toggle public void consumeEvents(Listener listener)
93    {
94  64166 while (!isEmpty()) {
95  49230 Event event = remove();
96  49231 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  61933 toggle private void saveEvent(EventType eventType, Object... objects)
107    {
108  61955 offer(new Event(eventType, objects));
109    }
110   
 
111  28 toggle @Override
112    public void beginDefinitionDescription()
113    {
114  28 saveEvent(EventType.BEGIN_DEFINITION_DESCRIPTION);
115    }
116   
117    /**
118    * {@inheritDoc}
119    *
120    * @since 2.0RC1
121    */
 
122  29 toggle @Override
123    public void beginDefinitionList(Map<String, String> parameters)
124    {
125  29 saveEvent(EventType.BEGIN_DEFINITION_LIST, parameters);
126    }
127   
 
128  24 toggle @Override
129    public void beginDefinitionTerm()
130    {
131  24 saveEvent(EventType.BEGIN_DEFINITION_TERM);
132    }
133   
134    /**
135    * {@inheritDoc}
136    *
137    * @since 3.0M2
138    */
 
139  481 toggle @Override
140    public void beginDocument(MetaData metadata)
141    {
142  481 saveEvent(EventType.BEGIN_DOCUMENT, metadata);
143    }
144   
 
145  71 toggle @Override
146    public void beginGroup(Map<String, String> parameters)
147    {
148  71 saveEvent(EventType.BEGIN_GROUP, parameters);
149    }
150   
 
151  278 toggle @Override
152    public void beginFormat(Format format, Map<String, String> parameters)
153    {
154  278 saveEvent(EventType.BEGIN_FORMAT, format, parameters);
155    }
156   
 
157  90 toggle @Override
158    public void beginHeader(HeaderLevel level, String id, Map<String, String> parameters)
159    {
160  90 saveEvent(EventType.BEGIN_HEADER, level, id, parameters);
161    }
162   
163    /**
164    * {@inheritDoc}
165    *
166    * @since 2.5RC1
167    */
 
168  732 toggle @Override
169    public void beginLink(ResourceReference reference, boolean freestanding, Map<String, String> parameters)
170    {
171  732 saveEvent(EventType.BEGIN_LINK, reference, freestanding, parameters);
172    }
173   
 
174  191 toggle @Override
175    public void beginList(ListType type, Map<String, String> parameters)
176    {
177  191 saveEvent(EventType.BEGIN_LIST, type, parameters);
178    }
179   
 
180  0 toggle @Override
181    public void beginListItem()
182    {
183  0 saveEvent(EventType.BEGIN_LIST_ITEM);
184    }
185   
 
186  271 toggle @Override
187    public void beginListItem(Map<String, String> parameters)
188    {
189  271 saveEvent(EventType.BEGIN_LIST_ITEM, parameters);
190    }
191   
 
192  71 toggle @Override
193    public void beginMacroMarker(String name, Map<String, String> parameters, String content, boolean isInline)
194    {
195  71 saveEvent(EventType.BEGIN_MACRO_MARKER, name, parameters, content, isInline);
196    }
197   
 
198  472 toggle @Override
199    public void beginParagraph(Map<String, String> parameters)
200    {
201  472 saveEvent(EventType.BEGIN_PARAGRAPH, parameters);
202    }
203   
 
204  13 toggle @Override
205    public void beginQuotation(Map<String, String> parameters)
206    {
207  13 saveEvent(EventType.BEGIN_QUOTATION, parameters);
208    }
209   
 
210  21 toggle @Override
211    public void beginQuotationLine()
212    {
213  21 saveEvent(EventType.BEGIN_QUOTATION_LINE);
214    }
215   
 
216  95 toggle @Override
217    public void beginSection(Map<String, String> parameters)
218    {
219  95 saveEvent(EventType.BEGIN_SECTION, parameters);
220    }
221   
 
222  38 toggle @Override
223    public void beginTable(Map<String, String> parameters)
224    {
225  38 saveEvent(EventType.BEGIN_TABLE, parameters);
226    }
227   
 
228  79 toggle @Override
229    public void beginTableCell(Map<String, String> parameters)
230    {
231  79 saveEvent(EventType.BEGIN_TABLE_CELL, parameters);
232    }
233   
 
234  44 toggle @Override
235    public void beginTableHeadCell(Map<String, String> parameters)
236    {
237  44 saveEvent(EventType.BEGIN_TABLE_HEAD_CELL, parameters);
238    }
239   
 
240  67 toggle @Override
241    public void beginTableRow(Map<String, String> parameters)
242    {
243  67 saveEvent(EventType.BEGIN_TABLE_ROW, parameters);
244    }
245   
246    /**
247    * {@inheritDoc}
248    *
249    * @since 3.0M2
250    */
 
251  13 toggle @Override
252    public void beginMetaData(MetaData metadata)
253    {
254  13 saveEvent(EventType.BEGIN_METADATA, metadata);
255    }
256   
 
257  28 toggle @Override
258    public void endDefinitionDescription()
259    {
260  28 saveEvent(EventType.END_DEFINITION_DESCRIPTION);
261    }
262   
263    /**
264    * {@inheritDoc}
265    *
266    * @since 2.0RC1
267    */
 
268  29 toggle @Override
269    public void endDefinitionList(Map<String, String> parameters)
270    {
271  29 saveEvent(EventType.END_DEFINITION_LIST, parameters);
272    }
273   
 
274  24 toggle @Override
275    public void endDefinitionTerm()
276    {
277  24 saveEvent(EventType.END_DEFINITION_TERM);
278    }
279   
280    /**
281    * {@inheritDoc}
282    *
283    * @since 3.0M2
284    */
 
285  771 toggle @Override
286    public void endDocument(MetaData metadata)
287    {
288  771 saveEvent(EventType.END_DOCUMENT, metadata);
289    }
290   
 
291  71 toggle @Override
292    public void endGroup(Map<String, String> parameters)
293    {
294  71 saveEvent(EventType.END_GROUP, parameters);
295    }
296   
 
297  278 toggle @Override
298    public void endFormat(Format format, Map<String, String> parameters)
299    {
300  278 saveEvent(EventType.END_FORMAT, format, parameters);
301    }
302   
 
303  90 toggle @Override
304    public void endHeader(HeaderLevel level, String id, Map<String, String> parameters)
305    {
306  90 saveEvent(EventType.END_HEADER, level, id, parameters);
307    }
308   
309    /**
310    * {@inheritDoc}
311    *
312    * @since 2.5RC1
313    */
 
314  732 toggle @Override
315    public void endLink(ResourceReference reference, boolean freestanding, Map<String, String> parameters)
316    {
317  732 saveEvent(EventType.END_LINK, reference, freestanding, parameters);
318    }
319   
 
320  191 toggle @Override
321    public void endList(ListType type, Map<String, String> parameters)
322    {
323  191 saveEvent(EventType.END_LIST, type, parameters);
324    }
325   
 
326  322 toggle @Override
327    public void endListItem()
328    {
329  322 saveEvent(EventType.END_LIST_ITEM);
330    }
331