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; |
21 |
|
|
22 |
|
import java.util.Collections; |
23 |
|
import java.util.HashMap; |
24 |
|
import java.util.HashSet; |
25 |
|
import java.util.Map; |
26 |
|
import java.util.Properties; |
27 |
|
import java.util.Set; |
28 |
|
|
29 |
|
import javax.inject.Inject; |
30 |
|
import javax.inject.Singleton; |
31 |
|
|
32 |
|
import org.xwiki.component.annotation.Component; |
33 |
|
import org.xwiki.rendering.macro.MacroCategoryManager; |
34 |
|
import org.xwiki.rendering.macro.MacroId; |
35 |
|
import org.xwiki.rendering.macro.MacroLookupException; |
36 |
|
import org.xwiki.rendering.macro.MacroManager; |
37 |
|
import org.xwiki.rendering.syntax.Syntax; |
38 |
|
import org.xwiki.rendering.transformation.macro.MacroTransformationConfiguration; |
39 |
|
|
40 |
|
|
41 |
|
@link |
42 |
|
|
43 |
|
@version |
44 |
|
@since |
45 |
|
|
46 |
|
@Component |
47 |
|
@Singleton |
|
|
| 97.3% |
Uncovered Elements: 1 (37) |
Complexity: 11 |
Complexity Density: 0.5 |
|
48 |
|
public class DefaultMacroCategoryManager implements MacroCategoryManager |
49 |
|
{ |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
@Inject |
54 |
|
private MacroTransformationConfiguration configuration; |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
@Inject |
60 |
|
private MacroManager macroManager; |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
65 |
|
private interface MacroMatcher |
66 |
|
{ |
67 |
|
|
68 |
|
@param |
69 |
|
@return |
70 |
|
|
71 |
|
boolean match(MacroId macroId); |
72 |
|
} |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
74 |
1 |
@Override... |
75 |
|
public Set<String> getMacroCategories() throws MacroLookupException |
76 |
|
{ |
77 |
1 |
return getMacroCategories(null); |
78 |
|
} |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
80 |
1 |
@Override... |
81 |
|
public Set<String> getMacroCategories(final Syntax syntax) throws MacroLookupException |
82 |
|
{ |
83 |
1 |
Set<String> categories = getMacroIdsByCategory(new MacroMatcher() |
84 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
85 |
8 |
@Override... |
86 |
|
public boolean match(MacroId macroId) |
87 |
|
{ |
88 |
|
|
89 |
8 |
return syntax == null || macroId.getSyntax() == null || macroId.getSyntax() == syntax; |
90 |
|
} |
91 |
|
}).keySet(); |
92 |
1 |
return Collections.unmodifiableSet(categories); |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
95 |
2 |
@Override... |
96 |
|
public Set<MacroId> getMacroIds(String category) throws MacroLookupException |
97 |
|
{ |
98 |
2 |
return getMacroIds(category, null); |
99 |
|
} |
100 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
101 |
5 |
@Override... |
102 |
|
public Set<MacroId> getMacroIds(String category, final Syntax syntax) throws MacroLookupException |
103 |
|
{ |
104 |
5 |
Set<MacroId> macros = getMacroIdsByCategory(new MacroMatcher() |
105 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
106 |
47 |
@Override... |
107 |
|
public boolean match(MacroId macroId) |
108 |
|
{ |
109 |
|
|
110 |
47 |
return syntax == null || macroId.getSyntax() == null || macroId.getSyntax().equals(syntax); |
111 |
|
} |
112 |
|
}).get(category); |
113 |
5 |
return (null != macros) ? Collections.unmodifiableSet(macros) : Collections.<MacroId>emptySet(); |
114 |
|
} |
115 |
|
|
116 |
|
|
117 |
|
@param |
118 |
|
@return |
119 |
|
@exception |
120 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 4 |
Complexity Density: 0.29 |
|
121 |
6 |
private Map<String, Set<MacroId>> getMacroIdsByCategory(MacroMatcher matcher) throws MacroLookupException... |
122 |
|
{ |
123 |
6 |
Map<String, Set<MacroId>> result = new HashMap<String, Set<MacroId>>(); |
124 |
|
|
125 |
|
|
126 |
6 |
Set<MacroId> macroIds = this.macroManager.getMacroIds(); |
127 |
|
|
128 |
|
|
129 |
6 |
Properties categories = this.configuration.getCategories(); |
130 |
6 |
for (MacroId macroId : macroIds) { |
131 |
55 |
if (matcher.match(macroId)) { |
132 |
|
|
133 |
54 |
String category = categories.getProperty(macroId.toString()); |
134 |
|
|
135 |
|
|
136 |
54 |
if (category == null) { |
137 |
46 |
category = this.macroManager.getMacro(macroId).getDescriptor().getDefaultCategory(); |
138 |
|
} |
139 |
|
|
140 |
|
|
141 |
54 |
Set<MacroId> ids = result.get(category); |
142 |
54 |
if (ids == null) { |
143 |
18 |
ids = new HashSet<MacroId>(); |
144 |
|
} |
145 |
54 |
ids.add(macroId); |
146 |
54 |
result.put(category, ids); |
147 |
|
} |
148 |
|
} |
149 |
|
|
150 |
6 |
return result; |
151 |
|
} |
152 |
|
} |