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.colortheme; |
21 |
|
|
22 |
|
import javax.inject.Inject; |
23 |
|
import javax.inject.Provider; |
24 |
|
import javax.inject.Singleton; |
25 |
|
|
26 |
|
import org.apache.commons.lang3.StringUtils; |
27 |
|
import org.xwiki.component.annotation.Component; |
28 |
|
import org.xwiki.model.reference.DocumentReference; |
29 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
30 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
31 |
|
import org.xwiki.model.reference.WikiReference; |
32 |
|
import org.xwiki.security.authorization.AuthorizationManager; |
33 |
|
import org.xwiki.security.authorization.Right; |
34 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
35 |
|
|
36 |
|
import com.xpn.xwiki.XWiki; |
37 |
|
import com.xpn.xwiki.XWikiContext; |
38 |
|
import com.xpn.xwiki.web.XWikiRequest; |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
@since |
44 |
|
@version |
45 |
|
|
46 |
|
@Component(roles = CurrentColorThemeGetter.class) |
47 |
|
@Singleton |
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 6 |
Complexity Density: 0.46 |
|
48 |
|
public class CurrentColorThemeGetter |
49 |
|
{ |
50 |
|
private static final String COLOR_THEME_FIELD = "colorTheme"; |
51 |
|
|
52 |
|
@Inject |
53 |
|
private DocumentReferenceResolver<String> documentReferenceResolver; |
54 |
|
|
55 |
|
@Inject |
56 |
|
private EntityReferenceSerializer<String> entityReferenceSerializer; |
57 |
|
|
58 |
|
@Inject |
59 |
|
private Provider<XWikiContext> xcontextProvider; |
60 |
|
|
61 |
|
@Inject |
62 |
|
private WikiDescriptorManager wikiDescriptorManager; |
63 |
|
|
64 |
|
@Inject |
65 |
|
private AuthorizationManager authorizationManager; |
66 |
|
|
67 |
|
|
68 |
|
@param |
69 |
|
@return |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
4 |
public String getCurrentColorTheme(String fallbackValue)... |
72 |
|
{ |
73 |
4 |
return getCurrentColorTheme(true, fallbackValue); |
74 |
|
} |
75 |
|
|
76 |
|
|
77 |
|
@param |
78 |
|
@param |
79 |
|
@return |
80 |
|
@since |
81 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 5 |
Complexity Density: 0.42 |
|
82 |
2169 |
public String getCurrentColorTheme(boolean checkRights, String fallbackValue) ... |
83 |
|
{ |
84 |
|
|
85 |
2169 |
String wikiId = wikiDescriptorManager.getCurrentWikiId(); |
86 |
2169 |
XWikiContext context = xcontextProvider.get(); |
87 |
2169 |
XWiki xwiki = context.getWiki(); |
88 |
2169 |
XWikiRequest request = context.getRequest(); |
89 |
|
|
90 |
|
|
91 |
2167 |
String colorTheme = request.getParameter(COLOR_THEME_FIELD); |
92 |
2169 |
if (StringUtils.isEmpty(colorTheme)) { |
93 |
|
|
94 |
1914 |
colorTheme = xwiki.getUserPreference(COLOR_THEME_FIELD, context); |
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
2169 |
DocumentReference colorThemeReference = |
99 |
|
documentReferenceResolver.resolve(colorTheme, new WikiReference(wikiId)); |
100 |
2169 |
colorTheme = entityReferenceSerializer.serialize(colorThemeReference); |
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
2169 |
if (!xwiki.exists(colorThemeReference, context) || (checkRights && !authorizationManager.hasAccess(Right.VIEW, |
106 |
|
context.getUserReference(), colorThemeReference))) { |
107 |
1930 |
colorTheme = fallbackValue; |
108 |
|
} |
109 |
|
|
110 |
2169 |
return colorTheme; |
111 |
|
} |
112 |
|
|
113 |
|
} |