1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rendering.internal.block; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import org.xwiki.rendering.block.Block; |
26 |
|
import org.xwiki.rendering.block.BlockFilter; |
27 |
|
import org.xwiki.rendering.block.MacroMarkerBlock; |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
@version |
38 |
|
@since |
39 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (33) |
Complexity: 11 |
Complexity Density: 0.55 |
|
40 |
|
public class ProtectedBlockFilter implements BlockFilter |
41 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
42 |
802626 |
@Override... |
43 |
|
public List<Block> filter(Block block) |
44 |
|
{ |
45 |
802626 |
List<Block> blocks = new ArrayList<Block>(); |
46 |
802626 |
if (!isProtectedBlock(block)) { |
47 |
802618 |
blocks.add(block); |
48 |
|
} |
49 |
802626 |
return blocks; |
50 |
|
} |
51 |
|
|
52 |
|
|
53 |
|
@param |
54 |
|
@return |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
56 |
809771 |
public List<Block> filter(List<Block> blocks)... |
57 |
|
{ |
58 |
809771 |
List<Block> filteredBlocks = new ArrayList<Block>(); |
59 |
809771 |
for (Block block : blocks) { |
60 |
802626 |
filteredBlocks.addAll(filter(block)); |
61 |
|
} |
62 |
809770 |
return filteredBlocks; |
63 |
|
} |
64 |
|
|
65 |
|
|
66 |
|
@param |
67 |
|
@return |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
69 |
802597 |
public Block getNextSibling(Block block)... |
70 |
|
{ |
71 |
802597 |
Block sibling = block.getNextSibling(); |
72 |
802604 |
while (sibling != null && isProtectedBlock(sibling)) { |
73 |
7 |
sibling = sibling.getNextSibling(); |
74 |
|
} |
75 |
802597 |
return sibling; |
76 |
|
} |
77 |
|
|
78 |
|
|
79 |
|
@param |
80 |
|
@param |
81 |
|
@param |
82 |
|
@param |
83 |
|
@return |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
85 |
3 |
public <T extends Block> List<T> getChildrenByType(Block block, Class<T> blockClass, boolean recurse)... |
86 |
|
{ |
87 |
3 |
List<T> typedBlocks = new ArrayList<T>(); |
88 |
3 |
for (Block child : filter(block.getChildren())) { |
89 |
22 |
if (blockClass.isAssignableFrom(child.getClass())) { |
90 |
9 |
typedBlocks.add(blockClass.cast(child)); |
91 |
|
} |
92 |
22 |
if (recurse && !child.getChildren().isEmpty()) { |
93 |
1 |
typedBlocks.addAll(getChildrenByType(child, blockClass, true)); |
94 |
|
} |
95 |
|
} |
96 |
|
|
97 |
3 |
return typedBlocks; |
98 |
|
} |
99 |
|
|
100 |
|
|
101 |
|
@param |
102 |
|
@return |
103 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
104 |
1564845 |
private boolean isProtectedBlock(Block block)... |
105 |
|
{ |
106 |
1564845 |
return (block instanceof MacroMarkerBlock) |
107 |
|
&& "code".equals(((MacroMarkerBlock) block).getId()); |
108 |
|
} |
109 |
|
} |