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.macro.dashboard; |
21 |
|
|
22 |
|
import java.util.Collections; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import javax.inject.Inject; |
26 |
|
import javax.inject.Named; |
27 |
|
import javax.inject.Singleton; |
28 |
|
|
29 |
|
import org.xwiki.component.annotation.Component; |
30 |
|
import org.xwiki.rendering.block.Block; |
31 |
|
import org.xwiki.rendering.block.GroupBlock; |
32 |
|
import org.xwiki.rendering.block.HeaderBlock; |
33 |
|
import org.xwiki.rendering.listener.HeaderLevel; |
34 |
|
import org.xwiki.rendering.macro.dashboard.Gadget; |
35 |
|
import org.xwiki.rendering.macro.dashboard.GadgetRenderer; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
@version |
42 |
|
@since |
43 |
|
|
44 |
|
@Component |
45 |
|
@Singleton |
|
|
| 89.5% |
Uncovered Elements: 2 (19) |
Complexity: 2 |
Complexity Density: 0.12 |
|
46 |
|
public class DefaultGadgetRenderer implements GadgetRenderer |
47 |
|
{ |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
protected static final String CLASS = "class"; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
protected static final String ID = "id"; |
57 |
|
|
58 |
|
@Inject |
59 |
|
@Named("empty") |
60 |
|
private XDOMChecker emptyXDOMChecker; |
61 |
|
|
|
|
| 88.9% |
Uncovered Elements: 2 (18) |
Complexity: 2 |
Complexity Density: 0.12 |
|
62 |
13 |
@Override... |
63 |
|
public List<Block> decorateGadget(Gadget gadget) |
64 |
|
{ |
65 |
13 |
List<Block> result; |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
13 |
if (!this.emptyXDOMChecker.check(gadget.getContent())) { |
70 |
|
|
71 |
13 |
HeaderBlock titleBlock = new HeaderBlock(gadget.getTitle(), HeaderLevel.LEVEL1); |
72 |
13 |
titleBlock.setParameter(CLASS, "gadget-title"); |
73 |
|
|
74 |
|
|
75 |
13 |
GroupBlock contentGroup = new GroupBlock(); |
76 |
13 |
contentGroup.setParameter(CLASS, "gadget-content"); |
77 |
13 |
contentGroup.addChildren(gadget.getContent()); |
78 |
|
|
79 |
|
|
80 |
13 |
GroupBlock gadgetBlock = new GroupBlock(); |
81 |
13 |
String idPrefix = "gadget"; |
82 |
13 |
gadgetBlock.setParameter(CLASS, idPrefix); |
83 |
|
|
84 |
13 |
gadgetBlock.setParameter(ID, idPrefix + "_" + gadget.getId()); |
85 |
13 |
gadgetBlock.addChild(titleBlock); |
86 |
13 |
gadgetBlock.addChild(contentGroup); |
87 |
|
|
88 |
13 |
result = Collections.singletonList(gadgetBlock); |
89 |
|
} else { |
90 |
0 |
result = Collections.emptyList(); |
91 |
|
} |
92 |
|
|
93 |
13 |
return result; |
94 |
|
} |
95 |
|
} |