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.wikibridge; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import javax.inject.Inject; |
26 |
|
import javax.inject.Named; |
27 |
|
import javax.inject.Provider; |
28 |
|
import javax.inject.Singleton; |
29 |
|
|
30 |
|
import org.slf4j.Logger; |
31 |
|
import org.xwiki.bridge.event.ApplicationReadyEvent; |
32 |
|
import org.xwiki.bridge.event.WikiReadyEvent; |
33 |
|
import org.xwiki.component.annotation.Component; |
34 |
|
import org.xwiki.observation.EventListener; |
35 |
|
import org.xwiki.observation.event.Event; |
36 |
|
import org.xwiki.rendering.macro.wikibridge.WikiMacroInitializer; |
37 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
@version |
43 |
|
@since |
44 |
|
|
45 |
|
@Component |
46 |
|
@Singleton |
47 |
|
@Named(WikiMacroInitializerListener.NAME) |
|
|
| 55.6% |
Uncovered Elements: 8 (18) |
Complexity: 7 |
Complexity Density: 0.64 |
|
48 |
|
public class WikiMacroInitializerListener implements EventListener |
49 |
|
{ |
50 |
|
static final String NAME = "WikiMacroInitializerListener"; |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
private static final List<Event> EVENTS = Arrays.asList(new ApplicationReadyEvent(), new WikiReadyEvent()); |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
@Inject |
61 |
|
private Provider<WikiMacroInitializer> macroInitializer; |
62 |
|
|
63 |
|
@Inject |
64 |
|
private WikiDescriptorManager wikiManager; |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
@Inject |
70 |
|
private Logger logger; |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
30 |
@Override... |
73 |
|
public List<Event> getEvents() |
74 |
|
{ |
75 |
30 |
return EVENTS; |
76 |
|
} |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
158 |
@Override... |
79 |
|
public String getName() |
80 |
|
{ |
81 |
158 |
return NAME; |
82 |
|
} |
83 |
|
|
|
|
| 38.5% |
Uncovered Elements: 8 (13) |
Complexity: 5 |
Complexity Density: 0.56 |
|
84 |
19 |
@Override... |
85 |
|
public void onEvent(Event event, Object source, Object data) |
86 |
|
{ |
87 |
19 |
WikiMacroInitializer initializer = this.macroInitializer.get(); |
88 |
|
|
89 |
19 |
if (event instanceof ApplicationReadyEvent) { |
90 |
19 |
try { |
91 |
19 |
initializer.registerExistingWikiMacros(wikiManager.getCurrentWikiId()); |
92 |
|
} catch (Exception e) { |
93 |
0 |
this.logger.error("Error while registering wiki macros.", e); |
94 |
|
} |
95 |
0 |
} else if (event instanceof WikiReadyEvent) { |
96 |
0 |
try { |
97 |
0 |
initializer.registerExistingWikiMacros(((WikiReadyEvent) event).getWikiId()); |
98 |
|
} catch (Exception e) { |
99 |
0 |
this.logger.error("Error while initializing wiki macro classes.", e); |
100 |
|
} |
101 |
|
} |
102 |
|
} |
103 |
|
} |