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

File MetaDataBlock.java

 

Coverage histogram

../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

4
21
9
1
135
66
12
0.57
2.33
9
1.33

Classes

Class Line # Actions
MetaDataBlock 37 21 0% 12 9
0.735294173.5%
 

Contributing tests

This file is covered by 1233 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.block;
21   
22    import java.util.Collections;
23    import java.util.List;
24   
25    import org.apache.commons.lang3.builder.EqualsBuilder;
26    import org.apache.commons.lang3.builder.HashCodeBuilder;
27    import org.xwiki.rendering.listener.Listener;
28    import org.xwiki.rendering.listener.MetaData;
29   
30    /**
31    * Represents any kind of MetaData in the XDOM (eg saving original blocks so that the XWiki Syntax Renderer can restore
32    * them after a transformation has been executed, source reference, etc).
33    *
34    * @version $Id: 7f201f0c73606fc85571ea6ed94482a38fa9efc8 $
35    * @since 3.0M2
36    */
 
37    public class MetaDataBlock extends AbstractBlock
38    {
39    /**
40    * Contains all MetaData for this Block and its children.
41    */
42    private MetaData metaData;
43   
44    /**
45    * @param childBlocks the list of children blocks of the block to construct
46    * @param metaData the metadata to set
47    * @see AbstractBlock#AbstractBlock(List)
48    */
 
49  58566 toggle public MetaDataBlock(List<? extends Block> childBlocks, MetaData metaData)
50    {
51  58567 super(childBlocks);
52  58566 this.metaData = metaData;
53    }
54   
55    /**
56    * Helper constructor.
57    *
58    * @param childBlocks the list of children blocks of the block to construct
59    * @param key the metadata key to set
60    * @param value the metadata value to set
61    * @see AbstractBlock#AbstractBlock(List)
62    */
 
63  0 toggle public MetaDataBlock(List<? extends Block> childBlocks, String key, Object value)
64    {
65  0 this(childBlocks, new MetaData(Collections.singletonMap(key, value)));
66    }
67   
68    /**
69    * @param childBlocks the list of children blocks of the block to construct
70    * @see AbstractBlock#AbstractBlock(List)
71    */
 
72  1 toggle public MetaDataBlock(List<? extends Block> childBlocks)
73    {
74  1 this(childBlocks, new MetaData());
75    }
76   
77    /**
78    * @return the metadata for this block, see {@link MetaData}
79    */
 
80  103638 toggle public MetaData getMetaData()
81    {
82  103638 return this.metaData;
83    }
84   
 
85  958 toggle @Override
86    public void before(Listener listener)
87    {
88  958 listener.beginMetaData(getMetaData());
89    }
90   
 
91  958 toggle @Override
92    public void after(Listener listener)
93    {
94  958 listener.endMetaData(getMetaData());
95    }
96   
 
97  44025 toggle @Override
98    public MetaDataBlock clone()
99    {
100  44026 MetaDataBlock cloned = (MetaDataBlock) super.clone();
101   
102  44024 cloned.metaData = new MetaData(this.metaData.getMetaData());
103   
104  44025 return cloned;
105    }
106   
 
107  5 toggle @Override
108    public boolean equals(Object obj)
109    {
110  5 if (obj == this) {
111  3 return true;
112    }
113   
114  2 if (obj instanceof MetaDataBlock && super.equals(obj)) {
115  2 EqualsBuilder builder = new EqualsBuilder();
116   
117  2 builder.append(getMetaData(), ((MetaDataBlock) obj).getMetaData());
118   
119  2 return builder.isEquals();
120    }
121   
122  0 return false;
123    }
124   
 
125  0 toggle @Override
126    public int hashCode()
127    {
128  0 HashCodeBuilder builder = new HashCodeBuilder();
129   
130  0 builder.appendSuper(super.hashCode());
131  0 builder.append(getMetaData());
132   
133  0 return builder.toHashCode();
134    }
135    }