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

File MetaDataStateChainingListener.java

 

Coverage histogram

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

Code metrics

10
25
7
1
118
67
12
0.48
3.57
7
1.71

Classes

Class Line # Actions
MetaDataStateChainingListener 36 25 0% 12 0
1.0100%
 

Contributing tests

This file is covered by 552 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.chaining;
21   
22    import java.util.ArrayDeque;
23    import java.util.ArrayList;
24    import java.util.Deque;
25    import java.util.Iterator;
26    import java.util.List;
27   
28    import org.xwiki.rendering.listener.MetaData;
29   
30    /**
31    * Provides the accumulated MetaData for all the previous blocks.
32    *
33    * @version $Id: 926934d95736c60c1eb105e6736338c599d53952 $
34    * @since 3.0M2
35    */
 
36    public class MetaDataStateChainingListener extends AbstractChainingListener
37    {
38    /**
39    * @see #getMetaData(String)
40    */
41    private Deque<MetaData> metaDataStack = new ArrayDeque<MetaData>();
42   
43    /**
44    * @param listenerChain see {@link #getListenerChain()}
45    */
 
46  19599 toggle public MetaDataStateChainingListener(ListenerChain listenerChain)
47    {
48  19598 setListenerChain(listenerChain);
49    }
50   
51    /**
52    * @param <T> the type of the value for the passed key
53    * @param key the key for which to find the value
54    * @return the accumulated MetaData during all the previous begin/endMetaData events
55    */
 
56  1296 toggle public <T> List<T> getAllMetaData(String key)
57    {
58  1296 List<T> result = new ArrayList<T>();
59  1296 if (!this.metaDataStack.isEmpty()) {
60  1198 Iterator<MetaData> it = this.metaDataStack.descendingIterator();
61  2506 while (it.hasNext()) {
62  1308 MetaData metaData = it.next();
63  1308 Object value = metaData.getMetaData(key);
64  1308 if (value != null) {
65  985 result.add((T) metaData.getMetaData(key));
66    }
67    }
68    }
69  1296 return result;
70    }
71   
72    /**
73    * @param <T> the type of the value for the passed key
74    * @param key the key for which to find the value
75    * @return the accumulated MetaData during all the previous begin/endMetaData events, for the passed key
76    */
 
77  19 toggle public <T> T getMetaData(String key)
78    {
79  19 T result = null;
80  19 if (!this.metaDataStack.isEmpty()) {
81  18 for (MetaData metaData : this.metaDataStack) {
82  29 result = (T) metaData.getMetaData(key);
83  29 if (result != null) {
84  13 break;
85    }
86    }
87    }
88  19 return result;
89    }
90   
 
91  18115 toggle @Override
92    public void beginDocument(MetaData metaData)
93    {
94  18114 this.metaDataStack.push(metaData);
95  18112 super.beginDocument(metaData);
96    }
97   
 
98  18113 toggle @Override
99    public void endDocument(MetaData metaData)
100    {
101  18112 super.endDocument(metaData);
102  18114 this.metaDataStack.pop();
103    }
104   
 
105  765 toggle @Override
106    public void beginMetaData(MetaData metaData)
107    {
108  765 this.metaDataStack.push(metaData);
109  765 super.beginMetaData(metaData);
110    }
111   
 
112  765 toggle @Override
113    public void endMetaData(MetaData metaData)
114    {
115  765 super.endMetaData(metaData);
116  765 this.metaDataStack.pop();
117    }
118    }