1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.repository.internal; |
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.DocumentCreatingEvent; |
32 |
|
import org.xwiki.bridge.event.DocumentUpdatingEvent; |
33 |
|
import org.xwiki.component.annotation.Component; |
34 |
|
import org.xwiki.observation.EventListener; |
35 |
|
import org.xwiki.observation.event.Event; |
36 |
|
|
37 |
|
import com.xpn.xwiki.XWikiException; |
38 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
39 |
|
import com.xpn.xwiki.objects.BaseObject; |
40 |
|
|
41 |
|
@Component |
42 |
|
@Named("ExtensionUpdaterListener") |
43 |
|
@Singleton |
|
|
| 92.3% |
Uncovered Elements: 1 (13) |
Complexity: 5 |
Complexity Density: 0.62 |
|
44 |
|
public class ExtensionUpdaterListener implements EventListener |
45 |
|
{ |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
private static final List<Event> EVENTS = Arrays.<Event> asList(new DocumentCreatingEvent(), |
50 |
|
new DocumentUpdatingEvent()); |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
@Inject |
56 |
|
private Logger logger; |
57 |
|
|
58 |
|
@Inject |
59 |
|
private Provider<RepositoryManager> repositoryManagerProvider; |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
61 |
2 |
@Override... |
62 |
|
public List<Event> getEvents() |
63 |
|
{ |
64 |
2 |
return EVENTS; |
65 |
|
} |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
8 |
@Override... |
68 |
|
public String getName() |
69 |
|
{ |
70 |
8 |
return "ExtensionUpdaterListener"; |
71 |
|
} |
72 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
73 |
87 |
@Override... |
74 |
|
public void onEvent(Event event, Object source, Object data) |
75 |
|
{ |
76 |
87 |
XWikiDocument document = (XWikiDocument) source; |
77 |
|
|
78 |
87 |
BaseObject extensionObject = document.getXObject(XWikiRepositoryModel.EXTENSION_CLASSREFERENCE); |
79 |
|
|
80 |
87 |
if (extensionObject != null) { |
81 |
45 |
try { |
82 |
45 |
this.repositoryManagerProvider.get().validateExtension(document, false); |
83 |
|
} catch (XWikiException e) { |
84 |
0 |
this.logger.error("Failed to validate extension in document [{}]", document.getDocumentReference(), e); |
85 |
|
} |
86 |
|
} |
87 |
|
} |
88 |
|
|
89 |
|
} |