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.content; |
21 |
|
|
22 |
|
import java.io.StringReader; |
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.component.manager.ComponentLookupException; |
31 |
|
import org.xwiki.component.manager.ComponentManager; |
32 |
|
import org.xwiki.rendering.block.Block; |
33 |
|
import org.xwiki.rendering.macro.AbstractMacro; |
34 |
|
import org.xwiki.rendering.macro.MacroExecutionException; |
35 |
|
import org.xwiki.rendering.macro.content.ContentMacroParameters; |
36 |
|
import org.xwiki.rendering.macro.descriptor.DefaultContentDescriptor; |
37 |
|
import org.xwiki.rendering.parser.ParseException; |
38 |
|
import org.xwiki.rendering.parser.Parser; |
39 |
|
import org.xwiki.rendering.syntax.Syntax; |
40 |
|
import org.xwiki.rendering.transformation.MacroTransformationContext; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
@version |
47 |
|
@since |
48 |
|
|
49 |
|
@Component |
50 |
|
@Named("content") |
51 |
|
@Singleton |
|
|
| 76.9% |
Uncovered Elements: 3 (13) |
Complexity: 6 |
Complexity Density: 0.67 |
|
52 |
|
public class ContentMacro extends AbstractMacro<ContentMacroParameters> |
53 |
|
{ |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
private static final String DESCRIPTION = "Allows writing content in any wiki markup"; |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
private static final String CONTENT_DESCRIPTION = "The content to execute"; |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
@Inject |
68 |
|
private ComponentManager componentManager; |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
73 |
2 |
public ContentMacro()... |
74 |
|
{ |
75 |
2 |
super("Content", DESCRIPTION, new DefaultContentDescriptor(CONTENT_DESCRIPTION), ContentMacroParameters.class); |
76 |
2 |
setDefaultCategory(DEFAULT_CATEGORY_CONTENT); |
77 |
|
} |
78 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
0 |
@Override... |
80 |
|
public boolean supportsInlineMode() |
81 |
|
{ |
82 |
0 |
return false; |
83 |
|
} |
84 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
85 |
2 |
@Override... |
86 |
|
public List<Block> execute(ContentMacroParameters parameters, String content, MacroTransformationContext context) |
87 |
|
throws MacroExecutionException |
88 |
|
{ |
89 |
2 |
try { |
90 |
2 |
return getSyntaxParser(parameters.getSyntax()).parse(new StringReader(content)).getChildren(); |
91 |
|
} catch (ParseException e) { |
92 |
0 |
throw new MacroExecutionException( |
93 |
|
String.format("Failed to parse macro content in syntax [%s]", parameters.getSyntax()), e); |
94 |
|
} |
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
@param |
101 |
|
@return |
102 |
|
@throws |
103 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
104 |
2 |
protected Parser getSyntaxParser(Syntax syntax) throws MacroExecutionException... |
105 |
|
{ |
106 |
2 |
try { |
107 |
2 |
return this.componentManager.getInstance(Parser.class, syntax.toIdString()); |
108 |
|
} catch (ComponentLookupException e) { |
109 |
1 |
throw new MacroExecutionException(String.format("Cannot find Parser for syntax [%s]", syntax.toIdString())); |
110 |
|
} |
111 |
|
} |
112 |
|
} |