1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.icon.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.Singleton; |
28 |
|
|
29 |
|
import org.xwiki.bridge.event.DocumentDeletedEvent; |
30 |
|
import org.xwiki.bridge.event.DocumentUpdatedEvent; |
31 |
|
import org.xwiki.component.annotation.Component; |
32 |
|
import org.xwiki.icon.IconSetCache; |
33 |
|
import org.xwiki.model.reference.LocalDocumentReference; |
34 |
|
import org.xwiki.observation.EventListener; |
35 |
|
import org.xwiki.observation.event.Event; |
36 |
|
|
37 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
38 |
|
import com.xpn.xwiki.objects.BaseObject; |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
@since |
44 |
|
@version |
45 |
|
|
46 |
|
@Component |
47 |
|
@Named("iconTheme") |
48 |
|
@Singleton |
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 5 |
Complexity Density: 0.5 |
|
49 |
|
public class IconThemeListener implements EventListener |
50 |
|
{ |
51 |
|
private static final LocalDocumentReference ICON_THEME_CLASS = |
52 |
|
new LocalDocumentReference("IconThemesCode", "IconThemeClass"); |
53 |
|
|
54 |
|
@Inject |
55 |
|
private IconSetCache iconSetCache; |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
361 |
@Override... |
58 |
|
public String getName() |
59 |
|
{ |
60 |
361 |
return "Icon Theme listener."; |
61 |
|
} |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
63 |
61 |
@Override... |
64 |
|
public List<Event> getEvents() |
65 |
|
{ |
66 |
61 |
return Arrays.<Event>asList( |
67 |
|
new DocumentUpdatedEvent(), |
68 |
|
new DocumentDeletedEvent()); |
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
71 |
586 |
@Override... |
72 |
|
public void onEvent(Event event, Object source, Object data) |
73 |
|
{ |
74 |
586 |
XWikiDocument document = (XWikiDocument) source; |
75 |
|
|
76 |
586 |
List<BaseObject> iconThemeObjects = document.getXObjects(ICON_THEME_CLASS); |
77 |
586 |
if (iconThemeObjects != null && !iconThemeObjects.isEmpty()) { |
78 |
|
|
79 |
1 |
iconSetCache.clear(document.getDocumentReference()); |
80 |
|
|
81 |
1 |
BaseObject iconThemeObj = iconThemeObjects.get(0); |
82 |
1 |
String iconThemeName = iconThemeObj.getStringValue("name"); |
83 |
1 |
String currentWiki = document.getDocumentReference().getWikiReference().getName(); |
84 |
1 |
iconSetCache.clear(iconThemeName, currentWiki); |
85 |
|
} |
86 |
|
} |
87 |
|
} |