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

File EmptyXDOMChecker.java

 

Coverage histogram

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

Code metrics

4
11
3
1
75
38
5
0.45
3.67
3
1.67

Classes

Class Line # Actions
EmptyXDOMChecker 45 11 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 5 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.internal.macro.dashboard;
21   
22    import java.util.List;
23   
24    import javax.inject.Named;
25    import javax.inject.Singleton;
26   
27    import org.xwiki.component.annotation.Component;
28    import org.xwiki.rendering.block.Block;
29    import org.xwiki.rendering.block.MacroMarkerBlock;
30   
31    /**
32    * Checks if the passed Blocks represent some visually empty content or not. We consider it's empty when:
33    * <ul>
34    * <li>There are no blocks</li>
35    * <li>There's only 1 block, it's a {@link org.xwiki.rendering.block.MacroMarkerBlock} and it doesn't have
36    * children</li>
37    * </ul>
38    *
39    * @version $Id: 9f52a9207ec18fc2f0a8ee1008e6bd18a6ddc02c $
40    * @since 8.4RC1
41    */
42    @Component
43    @Named("empty")
44    @Singleton
 
45    public class EmptyXDOMChecker implements XDOMChecker
46    {
 
47  16 toggle @Override
48    public boolean check(List<Block> blocks)
49    {
50  16 return isContentEmpty(blocks);
51    }
52   
 
53  16 toggle private boolean isContentEmpty(List<Block> blocks)
54    {
55  16 boolean result = false;
56   
57  16 if (blocks.isEmpty()) {
58  1 result = true;
59    } else {
60  15 result = true;
61  15 for (Block block : blocks) {
62  16 if (!isMacroMarkerBlockAndEmpty(block)) {
63  13 result = false;
64  13 break;
65    }
66    }
67    }
68  16 return result;
69    }
70   
 
71  16 toggle private boolean isMacroMarkerBlockAndEmpty(Block block)
72    {
73  16 return block instanceof MacroMarkerBlock && block.getChildren().isEmpty();
74    }
75    }