1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.plugin; |
21 |
|
|
22 |
|
import java.lang.reflect.Method; |
23 |
|
import java.util.HashMap; |
24 |
|
import java.util.Map; |
25 |
|
import java.util.Vector; |
26 |
|
|
27 |
|
import org.apache.commons.lang3.StringUtils; |
28 |
|
import org.slf4j.Logger; |
29 |
|
import org.slf4j.LoggerFactory; |
30 |
|
|
31 |
|
import com.xpn.xwiki.XWikiContext; |
32 |
|
import com.xpn.xwiki.XWikiException; |
33 |
|
import com.xpn.xwiki.doc.XWikiAttachment; |
34 |
|
|
|
|
| 51.1% |
Uncovered Elements: 64 (131) |
Complexity: 43 |
Complexity Density: 0.45 |
|
35 |
|
public class XWikiPluginManager |
36 |
|
{ |
37 |
|
|
38 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(XWikiPluginManager.class); |
39 |
|
|
40 |
|
private Vector<String> plugins = new Vector<String>(); |
41 |
|
|
42 |
|
private Vector<String> pluginClassNames = new Vector<String>(); |
43 |
|
|
44 |
|
private Map<String, XWikiPluginInterface> plugins_classes = new HashMap<String, XWikiPluginInterface>(); |
45 |
|
|
46 |
|
private Map<String, Vector<XWikiPluginInterface>> functionList = |
47 |
|
new HashMap<String, Vector<XWikiPluginInterface>>(); |
48 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
49 |
31 |
public XWikiPluginManager()... |
50 |
|
{ |
51 |
|
} |
52 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
53 |
87 |
public XWikiPluginManager(String classList, XWikiContext context)... |
54 |
|
{ |
55 |
87 |
String[] classNames = StringUtils.split(classList, " ,"); |
56 |
87 |
addPlugins(classNames, context); |
57 |
|
} |
58 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
59 |
0 |
public XWikiPluginManager(String[] classNames, XWikiContext context)... |
60 |
|
{ |
61 |
0 |
addPlugins(classNames, context); |
62 |
|
} |
63 |
|
|
|
|
| 70.4% |
Uncovered Elements: 8 (27) |
Complexity: 5 |
Complexity Density: 0.24 |
|
64 |
170 |
@SuppressWarnings("unchecked")... |
65 |
|
public void addPlugin(String name, String className, XWikiContext context) |
66 |
|
{ |
67 |
170 |
if (this.pluginClassNames.contains(className)) { |
68 |
0 |
if (LOGGER.isInfoEnabled()) { |
69 |
0 |
LOGGER.info(String.format("Skipping already registered plugin [%s]", name)); |
70 |
|
} |
71 |
0 |
return; |
72 |
|
} |
73 |
170 |
try { |
74 |
170 |
Class<?>[] classes = new Class<?>[3]; |
75 |
170 |
classes[0] = String.class; |
76 |
170 |
classes[1] = String.class; |
77 |
170 |
classes[2] = context.getClass(); |
78 |
170 |
Object[] args = new Object[3]; |
79 |
170 |
args[0] = name; |
80 |
170 |
args[1] = className; |
81 |
170 |
args[2] = context; |
82 |
170 |
Class<XWikiPluginInterface> pluginClass = |
83 |
|
(Class<XWikiPluginInterface>) Class.forName(className, true, Thread.currentThread() |
84 |
|
.getContextClassLoader()); |
85 |
170 |
XWikiPluginInterface plugin = pluginClass.getConstructor(classes).newInstance(args); |
86 |
170 |
if (plugin != null) { |
87 |
170 |
this.plugins.add(plugin.getName()); |
88 |
170 |
this.plugins_classes.put(plugin.getName(), plugin); |
89 |
170 |
this.pluginClassNames.add(className); |
90 |
170 |
initPlugin(plugin, pluginClass, context); |
91 |
|
} |
92 |
|
} catch (Exception ex) { |
93 |
|
|
94 |
0 |
LOGGER.error("Cannot initialize plugin [" + className + "]. This plugin will not be available.", ex); |
95 |
|
} |
96 |
|
} |
97 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
98 |
0 |
public void removePlugin(String className)... |
99 |
|
{ |
100 |
0 |
this.plugins.remove(className); |
101 |
0 |
Object plugin = this.plugins_classes.get(className); |
102 |
0 |
this.plugins_classes.remove(className); |
103 |
|
|
104 |
0 |
for (String name : this.functionList.keySet()) { |
105 |
0 |
Vector<XWikiPluginInterface> pluginList = this.functionList.get(name); |
106 |
0 |
pluginList.remove(plugin); |
107 |
|
} |
108 |
|
} |
109 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
110 |
119 |
public void addPlugins(String[] classNames, XWikiContext context)... |
111 |
|
{ |
112 |
119 |
if (context.getURLFactory() == null) { |
113 |
87 |
context |
114 |
|
.setURLFactory(context.getWiki().getURLFactoryService().createURLFactory(context.getMode(), context)); |
115 |
|
} |
116 |
119 |
initInterface(); |
117 |
119 |
for (String className : classNames) { |
118 |
170 |
addPlugin(className, className, context); |
119 |
|
} |
120 |
|
} |
121 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
122 |
21955 |
public XWikiPluginInterface getPlugin(String className)... |
123 |
|
{ |
124 |
21955 |
return this.plugins_classes.get(className); |
125 |
|
} |
126 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
127 |
78496 |
public Vector<String> getPlugins()... |
128 |
|
{ |
129 |
78480 |
return this.plugins; |
130 |
|
} |
131 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
132 |
0 |
public void setPlugins(Vector<String> plugins)... |
133 |
|
{ |
134 |
0 |
this.plugins = plugins; |
135 |
|
} |
136 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
137 |
150 |
public void initInterface()... |
138 |
|
{ |
139 |
150 |
for (Method method : XWikiPluginInterface.class.getMethods()) { |
140 |
2250 |
String name = method.getName(); |
141 |
2250 |
this.functionList.put(name, new Vector<XWikiPluginInterface>()); |
142 |
|
} |
143 |
|
} |
144 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
145 |
170 |
public void initPlugin(Object plugin, Class<XWikiPluginInterface> pluginClass, XWikiContext context)... |
146 |
|
throws XWikiException |
147 |
|
{ |
148 |
170 |
for (Method method : pluginClass.getDeclaredMethods()) { |
149 |
939 |
String name = method.getName(); |
150 |
939 |
if (this.functionList.containsKey(name)) { |
151 |
382 |
this.functionList.get(name).add((XWikiPluginInterface) plugin); |
152 |
|
} |
153 |
|
} |
154 |
170 |
((XWikiPluginInterface) plugin).init(context); |
155 |
|
} |
156 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
157 |
14021 |
public Vector<XWikiPluginInterface> getPlugins(String functionName)... |
158 |
|
{ |
159 |
14021 |
if (this.functionList.containsKey(functionName)) { |
160 |
14021 |
return this.functionList.get(functionName); |
161 |
|
} |
162 |
0 |
return null; |
163 |
|
} |
164 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
165 |
32 |
public void virtualInit(XWikiContext context)... |
166 |
|
{ |
167 |
32 |
for (XWikiPluginInterface plugin : getPlugins("virtualInit")) { |
168 |
8 |
try { |
169 |
8 |
plugin.virtualInit(context); |
170 |
|
} catch (Exception e) { |
171 |
|
} |
172 |
|
} |
173 |
|
} |
174 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
175 |
0 |
public void flushCache(XWikiContext context)... |
176 |
|
{ |
177 |
0 |
for (XWikiPluginInterface plugin : getPlugins("flushCache")) { |
178 |
0 |
try { |
179 |
0 |
plugin.flushCache(context); |
180 |
|
} catch (Exception e) { |
181 |
0 |
LOGGER.error("Failed to flush cache in plugin [" + plugin.getClass() + "]", e); |
182 |
|
} |
183 |
|
} |
184 |
|
} |
185 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
186 |
0 |
public String commonTagsHandler(String text, XWikiContext context)... |
187 |
|
{ |
188 |
0 |
for (XWikiPluginInterface plugin : getPlugins("commonTagsHandler")) { |
189 |
0 |
try { |
190 |
0 |
text = plugin.commonTagsHandler(text, context); |
191 |
|
} catch (Exception e) { |
192 |
|
} |
193 |
|
} |
194 |
0 |
return text; |
195 |
|
} |
196 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
197 |
0 |
public String startRenderingHandler(String text, XWikiContext context)... |
198 |
|
{ |
199 |
0 |
for (XWikiPluginInterface plugin : getPlugins("startRenderingHandler")) { |
200 |
0 |
try { |
201 |
0 |
text = plugin.startRenderingHandler(text, context); |
202 |
|
} catch (Exception e) { |
203 |
|
} |
204 |
|
} |
205 |
0 |
return text; |
206 |
|
} |
207 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
208 |
0 |
public String outsidePREHandler(String text, XWikiContext context)... |
209 |
|
{ |
210 |
0 |
for (XWikiPluginInterface plugin : getPlugins("outsidePREHandler")) { |
211 |
0 |
try { |
212 |
0 |
text = plugin.outsidePREHandler(text, context); |
213 |
|
} catch (Exception e) { |
214 |
|
} |
215 |
|
} |
216 |
0 |
return text; |
217 |
|
} |
218 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
219 |
0 |
public String insidePREHandler(String text, XWikiContext context)... |
220 |
|
{ |
221 |
0 |
for (XWikiPluginInterface plugin : getPlugins("insidePREHandler")) { |
222 |
0 |
try { |
223 |
0 |
text = plugin.insidePREHandler(text, context); |
224 |
|
} catch (Exception e) { |
225 |
|
} |
226 |
|
} |
227 |
0 |
return text; |
228 |
|
} |
229 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
230 |
0 |
public String endRenderingHandler(String text, XWikiContext context)... |
231 |
|
{ |
232 |
0 |
for (XWikiPluginInterface plugin : getPlugins("endRenderingHandler")) { |
233 |
0 |
try { |
234 |
0 |
text = plugin.endRenderingHandler(text, context); |
235 |
|
} catch (Exception e) { |
236 |
|
} |
237 |
|
} |
238 |
0 |
return text; |
239 |
|
} |
240 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
241 |
0 |
public void beginRendering(XWikiContext context)... |
242 |
|
{ |
243 |
0 |
for (XWikiPluginInterface plugin : getPlugins("beginRendering")) { |
244 |
0 |
try { |
245 |
0 |
plugin.beginRendering(context); |
246 |
|
} catch (Exception e) { |
247 |
|
} |
248 |
|
} |
249 |
|
} |
250 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
251 |
0 |
public void endRendering(XWikiContext context)... |
252 |
|
{ |
253 |
0 |
for (XWikiPluginInterface plugin : getPlugins("endRendering")) { |
254 |
0 |
try { |
255 |
0 |
plugin.endRendering(context); |
256 |
|
} catch (Exception e) { |
257 |
|
} |
258 |
|
} |
259 |
|
} |
260 |
|
|
|
|
| 33.3% |
Uncovered Elements: 2 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
261 |
6893 |
public void beginParsing(XWikiContext context)... |
262 |
|
{ |
263 |
6893 |
for (XWikiPluginInterface plugin : getPlugins("beginParsing")) { |
264 |
0 |
try { |
265 |
0 |
plugin.beginParsing(context); |
266 |
|
} catch (Exception e) { |
267 |
|
} |
268 |
|
} |
269 |
|
} |
270 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
271 |
6893 |
public String endParsing(String content, XWikiContext context)... |
272 |
|
{ |
273 |
6893 |
for (XWikiPluginInterface plugin : getPlugins("endParsing")) { |
274 |
34465 |
try { |
275 |
34465 |
content = plugin.endParsing(content, context); |
276 |
|
} catch (Exception e) { |
277 |
|
} |
278 |
|
} |
279 |
6893 |
return content; |
280 |
|
} |
281 |
|
|
|
|
| 50% |
Uncovered Elements: 3 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
282 |
207 |
public XWikiAttachment downloadAttachment(XWikiAttachment attachment, XWikiContext context)... |
283 |
|
{ |
284 |
208 |
XWikiAttachment attach = attachment; |
285 |
206 |
for (XWikiPluginInterface plugin : getPlugins("downloadAttachment")) { |
286 |
0 |
try { |
287 |
0 |
attach = plugin.downloadAttachment(attach, context); |
288 |
|
} catch (Exception ex) { |
289 |
0 |
LOGGER.warn("downloadAttachment failed for plugin [" + plugin.getName() + "]: " + ex.getMessage()); |
290 |
|
} |
291 |
|
} |
292 |
204 |
return attach; |
293 |
|
} |
294 |
|
} |