1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.template.internal.macro; |
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.macro.AbstractMacro; |
32 |
|
import org.xwiki.rendering.macro.MacroExecutionException; |
33 |
|
import org.xwiki.rendering.transformation.MacroTransformationContext; |
34 |
|
import org.xwiki.template.TemplateManager; |
35 |
|
import org.xwiki.template.macro.TemplateMacroParameters; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@version |
41 |
|
@since |
42 |
|
|
43 |
|
@Component |
44 |
|
@Named("template") |
45 |
|
@Singleton |
|
|
| 80% |
Uncovered Elements: 3 (15) |
Complexity: 5 |
Complexity Density: 0.5 |
|
46 |
|
public class TemplateMacro extends AbstractMacro<TemplateMacroParameters> |
47 |
|
{ |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
private static final String DESCRIPTION = "Insert a template."; |
52 |
|
|
53 |
|
@Inject |
54 |
|
private TemplateManager renderer; |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
59 |
14 |
public TemplateMacro()... |
60 |
|
{ |
61 |
14 |
super("Template", DESCRIPTION, TemplateMacroParameters.class); |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
14 |
setPriority(10); |
66 |
14 |
setDefaultCategory(DEFAULT_CATEGORY_INTERNAL); |
67 |
|
} |
68 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
69 |
0 |
@Override... |
70 |
|
public boolean supportsInlineMode() |
71 |
|
{ |
72 |
0 |
return true; |
73 |
|
} |
74 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
75 |
333 |
@Override... |
76 |
|
public List<Block> execute(TemplateMacroParameters parameters, String content, MacroTransformationContext context) |
77 |
|
throws MacroExecutionException |
78 |
|
{ |
79 |
333 |
if (parameters.isOutput()) { |
80 |
149 |
return this.renderer.getXDOMNoException(parameters.getName()).getChildren(); |
81 |
|
} else { |
82 |
184 |
try { |
83 |
184 |
this.renderer.execute(parameters.getName()); |
84 |
|
} catch (Exception e) { |
85 |
0 |
throw new MacroExecutionException("Failed to execute template [" + parameters.getName() + "]", e); |
86 |
|
} |
87 |
|
|
88 |
184 |
return Collections.emptyList(); |
89 |
|
} |
90 |
|
} |
91 |
|
} |