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
27   119   13   3.86
12   68   0.48   7
7     1.86  
1    
 
  MetaDataStateChainingListener       Line # 35 27 0% 13 0 100% 1.0
 
  (239)
 
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.ArrayList;
23    import java.util.List;
24    import java.util.ListIterator;
25    import java.util.Stack;
26   
27    import org.xwiki.rendering.listener.MetaData;
28   
29    /**
30    * Provides the accumulated MetaData for all the previous blocks.
31    *
32    * @version $Id: 9d3807aab410266e5d14622e0226cebb29b14f8e $
33    * @since 3.0M2
34    */
 
35    public class MetaDataStateChainingListener extends AbstractChainingListener
36    {
37    /**
38    * @see #getMetaData(String)
39    */
40    private Stack<MetaData> metaDataStack = new Stack<MetaData>();
41   
42    /**
43    * @param listenerChain see {@link #getListenerChain()}
44    */
 
45  248 toggle public MetaDataStateChainingListener(ListenerChain listenerChain)
46    {
47  248 setListenerChain(listenerChain);
48    }
49   
50    /**
51    * @param <T> the type of the value for the passed key
52    * @param key the key for which to find the value
53    * @return the accumulated MetaData during all the previous begin/endMetaData events
54    */
 
55  127 toggle public <T> List<T> getAllMetaData(String key)
56    {
57  127 List<T> result = new ArrayList<T>();
58  127 if (!this.metaDataStack.isEmpty()) {
59  125 ListIterator<MetaData> it = this.metaDataStack.listIterator();
60  253 while (it.hasNext()) {
61  128 MetaData metaData = it.next();
62  128 Object value = metaData.getMetaData(key);
63  128 if (value != null) {
64  3 result.add((T) metaData.getMetaData(key));
65    }
66    }
67    }
68  127 return result;
69    }
70   
71    /**
72    * @param <T> the type of the value for the passed key
73    * @param key the key for which to find the value
74    * @return the accumulated MetaData during all the previous begin/endMetaData events, for the passed key
75    */
 
76  19 toggle public <T> T getMetaData(String key)
77    {
78  19 T result = null;
79  19 if (!this.metaDataStack.isEmpty()) {
80  18 ListIterator<MetaData> it = this.metaDataStack.listIterator(this.metaDataStack.size());
81  34 while (it.hasPrevious()) {
82  29 MetaData metaData = it.previous();
83  29 result = (T) metaData.getMetaData(key);
84  29 if (result != null) {
85  13 break;
86    }
87    }
88    }
89  19 return result;
90    }
91   
 
92  236 toggle @Override
93    public void beginDocument(MetaData metaData)
94    {
95  236 this.metaDataStack.push(metaData);
96  236 super.beginDocument(metaData);
97    }
98   
 
99  236 toggle @Override
100    public void endDocument(MetaData metaData)
101    {
102  236 super.endDocument(metaData);
103  236 this.metaDataStack.pop();
104    }
105   
 
106  8 toggle @Override
107    public void beginMetaData(MetaData metaData)
108    {
109  8 this.metaDataStack.push(metaData);
110  8 super.beginMetaData(metaData);
111    }
112   
 
113  8 toggle @Override
114    public void endMetaData(MetaData metaData)
115    {
116  8 super.endMetaData(metaData);
117  8 this.metaDataStack.pop();
118    }
119    }