1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rendering.macro.container; |
21 |
|
|
22 |
|
import java.util.Collections; |
23 |
|
import java.util.HashMap; |
24 |
|
import java.util.List; |
25 |
|
import java.util.Map; |
26 |
|
|
27 |
|
import javax.inject.Inject; |
28 |
|
|
29 |
|
import org.apache.commons.lang3.StringUtils; |
30 |
|
import org.xwiki.component.manager.ComponentLookupException; |
31 |
|
import org.xwiki.component.manager.ComponentManager; |
32 |
|
import org.xwiki.rendering.block.Block; |
33 |
|
import org.xwiki.rendering.block.GroupBlock; |
34 |
|
import org.xwiki.rendering.macro.AbstractMacro; |
35 |
|
import org.xwiki.rendering.macro.MacroExecutionException; |
36 |
|
import org.xwiki.rendering.macro.descriptor.ContentDescriptor; |
37 |
|
import org.xwiki.rendering.transformation.MacroTransformationContext; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@param |
46 |
|
@version |
47 |
|
@since |
48 |
|
|
|
|
| 64.3% |
Uncovered Elements: 10 (28) |
Complexity: 9 |
Complexity Density: 0.53 |
|
49 |
|
public abstract class AbstractContainerMacro<P extends ContainerMacroParameters> extends AbstractMacro<P> |
50 |
|
{ |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
private static final String CLASS_ATTRIBUTE = "class"; |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
@Inject |
60 |
|
private ComponentManager componentManager; |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
@param |
66 |
|
@param |
67 |
|
@param |
68 |
|
@param |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
3 |
protected AbstractContainerMacro(String name, String description, ContentDescriptor contentDescriptor,... |
71 |
|
Class< ? > parametersBeanClass) |
72 |
|
{ |
73 |
3 |
super(name, description, contentDescriptor, parametersBeanClass); |
74 |
|
} |
75 |
|
|
|
|
| 70.6% |
Uncovered Elements: 5 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
76 |
3 |
@Override... |
77 |
|
public List<Block> execute(P parameters, String content, MacroTransformationContext context) |
78 |
|
throws MacroExecutionException |
79 |
|
{ |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
3 |
Map<String, String> containerParameters = new HashMap<String, String>(); |
84 |
3 |
if (parameters.isJustify()) { |
85 |
0 |
containerParameters.put(CLASS_ATTRIBUTE, "container-justified"); |
86 |
|
} |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
3 |
GroupBlock containerRoot = new GroupBlock(containerParameters); |
91 |
3 |
containerRoot.addChildren(getContent(parameters, content, context)); |
92 |
|
|
93 |
|
|
94 |
3 |
LayoutManager layoutManager = getLayoutManager(parameters.getLayoutStyle()); |
95 |
|
|
96 |
3 |
if (layoutManager != null) { |
97 |
3 |
layoutManager.layoutContainer(containerRoot); |
98 |
|
} |
99 |
|
|
100 |
|
|
101 |
3 |
if (StringUtils.isNotEmpty(parameters.getCssClass())) { |
102 |
0 |
containerRoot.setParameter(CLASS_ATTRIBUTE, parameters.getCssClass()); |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
3 |
return Collections.<Block> singletonList(containerRoot); |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
|
@param |
111 |
|
@return |
112 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
113 |
3 |
protected LayoutManager getLayoutManager(String layoutStyle)... |
114 |
|
{ |
115 |
3 |
try { |
116 |
3 |
return getComponentManager().getInstance(LayoutManager.class, layoutStyle); |
117 |
|
} catch (ComponentLookupException e) { |
118 |
|
|
119 |
0 |
return null; |
120 |
|
} |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
@param |
127 |
|
@param |
128 |
|
@param |
129 |
|
@return |
130 |
|
@throws |
131 |
|
|
132 |
|
protected abstract List<Block> getContent(P parameters, String content, MacroTransformationContext context) |
133 |
|
throws MacroExecutionException; |
134 |
|
|
135 |
|
|
136 |
|
@return |
137 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
138 |
0 |
protected ComponentManager getComponentManager()... |
139 |
|
{ |
140 |
0 |
return this.componentManager; |
141 |
|
} |
142 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
143 |
0 |
@Override... |
144 |
|
public boolean supportsInlineMode() |
145 |
|
{ |
146 |
0 |
return false; |
147 |
|
} |
148 |
|
} |