1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.lesscss.internal.listeners; |
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.DocumentCreatedEvent; |
30 |
|
import org.xwiki.bridge.event.DocumentDeletedEvent; |
31 |
|
import org.xwiki.bridge.event.DocumentUpdatedEvent; |
32 |
|
import org.xwiki.component.annotation.Component; |
33 |
|
import org.xwiki.lesscss.internal.cache.ColorThemeCache; |
34 |
|
import org.xwiki.lesscss.internal.cache.LESSResourcesCache; |
35 |
|
import org.xwiki.lesscss.internal.colortheme.ColorThemeReference; |
36 |
|
import org.xwiki.lesscss.internal.colortheme.ColorThemeReferenceFactory; |
37 |
|
import org.xwiki.model.reference.LocalDocumentReference; |
38 |
|
import org.xwiki.observation.EventListener; |
39 |
|
import org.xwiki.observation.event.Event; |
40 |
|
|
41 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
42 |
|
import com.xpn.xwiki.objects.BaseObject; |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
@since |
48 |
|
@version |
49 |
|
|
50 |
|
@Component |
51 |
|
@Named("lessColorTheme") |
52 |
|
@Singleton |
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 8 |
Complexity Density: 0.57 |
|
53 |
|
public class ColorThemeListener implements EventListener |
54 |
|
{ |
55 |
|
private static final LocalDocumentReference COLOR_THEME_CLASS = |
56 |
|
new LocalDocumentReference("ColorThemes", "ColorThemeClass"); |
57 |
|
|
58 |
|
private static final LocalDocumentReference FLAMINGO_THEME_CLASS = |
59 |
|
new LocalDocumentReference("FlamingoThemesCode", "ThemeClass"); |
60 |
|
|
61 |
|
@Inject |
62 |
|
private LESSResourcesCache lessResourcesCache; |
63 |
|
|
64 |
|
@Inject |
65 |
|
private ColorThemeCache colorThemeCache; |
66 |
|
|
67 |
|
@Inject |
68 |
|
private ColorThemeReferenceFactory colorThemeReferenceFactory; |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
481 |
@Override... |
71 |
|
public String getName() |
72 |
|
{ |
73 |
481 |
return "LESS Color Theme Listener"; |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
61 |
@Override... |
77 |
|
public List<Event> getEvents() |
78 |
|
{ |
79 |
61 |
return Arrays.<Event>asList( |
80 |
|
new DocumentCreatedEvent(), |
81 |
|
new DocumentUpdatedEvent(), |
82 |
|
new DocumentDeletedEvent()); |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 5 |
Complexity Density: 0.56 |
|
85 |
3969 |
@Override... |
86 |
|
public void onEvent(Event event, Object source, Object data) |
87 |
|
{ |
88 |
3969 |
XWikiDocument document = (XWikiDocument) source; |
89 |
|
|
90 |
3969 |
List<BaseObject> flamingoThemeObjects = document.getXObjects(FLAMINGO_THEME_CLASS); |
91 |
3969 |
if (flamingoThemeObjects != null && !flamingoThemeObjects.isEmpty()) { |
92 |
7 |
clearCacheFromColorTheme(document); |
93 |
7 |
return; |
94 |
|
} |
95 |
|
|
96 |
3962 |
List<BaseObject> colorThemeObjects = document.getXObjects(COLOR_THEME_CLASS); |
97 |
3962 |
if (colorThemeObjects != null && !colorThemeObjects.isEmpty()) { |
98 |
1 |
clearCacheFromColorTheme(document); |
99 |
1 |
return; |
100 |
|
} |
101 |
|
} |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
103 |
8 |
private void clearCacheFromColorTheme(XWikiDocument document)... |
104 |
|
{ |
105 |
8 |
ColorThemeReference colorThemeReference = |
106 |
|
colorThemeReferenceFactory.createReference(document.getDocumentReference()); |
107 |
8 |
lessResourcesCache.clearFromColorTheme(colorThemeReference); |
108 |
8 |
colorThemeCache.clearFromColorTheme(colorThemeReference); |
109 |
|
} |
110 |
|
} |