1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.lesscss; |
21 |
|
|
22 |
|
import javax.inject.Inject; |
23 |
|
import javax.inject.Named; |
24 |
|
import javax.inject.Provider; |
25 |
|
import javax.inject.Singleton; |
26 |
|
|
27 |
|
import org.apache.commons.lang3.exception.ExceptionUtils; |
28 |
|
import org.xwiki.component.annotation.Component; |
29 |
|
import org.xwiki.lesscss.compiler.LESSCompiler; |
30 |
|
import org.xwiki.lesscss.compiler.LESSCompilerException; |
31 |
|
import org.xwiki.lesscss.internal.cache.ColorThemeCache; |
32 |
|
import org.xwiki.lesscss.internal.cache.LESSResourcesCache; |
33 |
|
import org.xwiki.lesscss.internal.colortheme.ColorTheme; |
34 |
|
import org.xwiki.lesscss.internal.colortheme.ColorThemeReference; |
35 |
|
import org.xwiki.lesscss.internal.colortheme.ColorThemeReferenceFactory; |
36 |
|
import org.xwiki.lesscss.internal.colortheme.LESSColorThemeConverter; |
37 |
|
import org.xwiki.lesscss.internal.skin.SkinReference; |
38 |
|
import org.xwiki.lesscss.internal.skin.SkinReferenceFactory; |
39 |
|
import org.xwiki.lesscss.resources.LESSResourceReferenceFactory; |
40 |
|
import org.xwiki.script.service.ScriptService; |
41 |
|
import org.xwiki.security.authorization.AuthorizationManager; |
42 |
|
import org.xwiki.security.authorization.Right; |
43 |
|
|
44 |
|
import com.xpn.xwiki.XWikiContext; |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
@since |
50 |
|
@version |
51 |
|
|
52 |
|
@Component |
53 |
|
@Named("lesscss") |
54 |
|
@Singleton |
|
|
| 96.2% |
Uncovered Elements: 2 (53) |
Complexity: 18 |
Complexity Density: 0.47 |
|
55 |
|
public class LessCompilerScriptService implements ScriptService |
56 |
|
{ |
57 |
|
@Inject |
58 |
|
private LESSCompiler lessCompiler; |
59 |
|
|
60 |
|
@Inject |
61 |
|
private LESSResourceReferenceFactory lessResourceReferenceFactory; |
62 |
|
|
63 |
|
@Inject |
64 |
|
private LESSResourcesCache lessCache; |
65 |
|
|
66 |
|
@Inject |
67 |
|
private ColorThemeCache colorThemeCache; |
68 |
|
|
69 |
|
@Inject |
70 |
|
private Provider<XWikiContext> xcontextProvider; |
71 |
|
|
72 |
|
@Inject |
73 |
|
private LESSColorThemeConverter lessColorThemeConverter; |
74 |
|
|
75 |
|
@Inject |
76 |
|
private SkinReferenceFactory skinReferenceFactory; |
77 |
|
|
78 |
|
@Inject |
79 |
|
private ColorThemeReferenceFactory colorThemeReferenceFactory; |
80 |
|
|
81 |
|
@Inject |
82 |
|
private AuthorizationManager authorizationManager; |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
@param |
90 |
|
@return |
91 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
92 |
50 |
public String compileSkinFile(String fileName)... |
93 |
|
{ |
94 |
50 |
return compileSkinFile(fileName, false); |
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
@param |
103 |
|
@param |
104 |
|
@return |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
106 |
53 |
public String compileSkinFile(String fileName, boolean force)... |
107 |
|
{ |
108 |
53 |
try { |
109 |
53 |
return lessCompiler.compile(lessResourceReferenceFactory.createReferenceForSkinFile(fileName), false, true, |
110 |
|
force); |
111 |
|
} catch (LESSCompilerException e) { |
112 |
1 |
return ExceptionUtils.getRootCauseMessage(e); |
113 |
|
} |
114 |
|
} |
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
@param |
122 |
|
@param |
123 |
|
@return |
124 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
125 |
2 |
public String compileSkinFile(String fileName, String skin)... |
126 |
|
{ |
127 |
2 |
return compileSkinFile(fileName, skin, false); |
128 |
|
} |
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
@param |
136 |
|
@param |
137 |
|
@param |
138 |
|
@return |
139 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
140 |
5 |
public String compileSkinFile(String fileName, String skin, boolean force)... |
141 |
|
{ |
142 |
5 |
try { |
143 |
5 |
return lessCompiler.compile(lessResourceReferenceFactory.createReferenceForSkinFile(fileName), false, true, |
144 |
|
skin, force); |
145 |
|
} catch (LESSCompilerException e) { |
146 |
1 |
return ExceptionUtils.getRootCauseMessage(e); |
147 |
|
} |
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
@param |
154 |
|
@return |
155 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
156 |
2081 |
public ColorTheme getColorThemeFromSkinFile(String filename)... |
157 |
|
{ |
158 |
2077 |
try { |
159 |
2078 |
return lessColorThemeConverter.getColorThemeFromSkinFile(filename, false); |
160 |
|
} catch (LESSCompilerException e) { |
161 |
1 |
return new ColorTheme(); |
162 |
|
} |
163 |
|
} |
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
@param |
169 |
|
@param |
170 |
|
@return |
171 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
172 |
2 |
public ColorTheme getColorThemeFromSkinFile(String filename, String skin)... |
173 |
|
{ |
174 |
2 |
try { |
175 |
2 |
return lessColorThemeConverter.getColorThemeFromSkinFile(filename, skin, false); |
176 |
|
} catch (LESSCompilerException e) { |
177 |
1 |
return new ColorTheme(); |
178 |
|
} |
179 |
|
} |
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
@return |
184 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
185 |
2 |
public boolean clearCache()... |
186 |
|
{ |
187 |
2 |
XWikiContext xcontext = xcontextProvider.get(); |
188 |
|
|
189 |
|
|
190 |
2 |
if (!authorizationManager.hasAccess(Right.PROGRAM, xcontext.getDoc().getAuthorReference(), |
191 |
|
xcontext.getDoc().getDocumentReference())) { |
192 |
1 |
return false; |
193 |
|
} |
194 |
|
|
195 |
1 |
lessCache.clear(); |
196 |
1 |
colorThemeCache.clear(); |
197 |
1 |
return true; |
198 |
|
} |
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
@param |
204 |
|
@return |
205 |
|
|
|
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 3 |
Complexity Density: 0.33 |
|
206 |
2 |
public boolean clearCacheFromColorTheme(String colorTheme)... |
207 |
|
{ |
208 |
2 |
XWikiContext xcontext = xcontextProvider.get(); |
209 |
|
|
210 |
|
|
211 |
2 |
if (!authorizationManager.hasAccess(Right.PROGRAM, xcontext.getDoc().getAuthorReference(), |
212 |
|
xcontext.getDoc().getDocumentReference())) { |
213 |
1 |
return false; |
214 |
|
} |
215 |
|
|
216 |
1 |
try { |
217 |
1 |
ColorThemeReference colorThemeReference = colorThemeReferenceFactory.createReference(colorTheme); |
218 |
1 |
lessCache.clearFromColorTheme(colorThemeReference); |
219 |
1 |
colorThemeCache.clearFromColorTheme(colorThemeReference); |
220 |
1 |
return true; |
221 |
|
} catch (LESSCompilerException e) { |
222 |
0 |
return false; |
223 |
|
} |
224 |
|
} |
225 |
|
|
226 |
|
|
227 |
|
|
228 |
|
|
229 |
|
@param |
230 |
|
@return |
231 |
|
|
232 |
|
@since |
233 |
|
|
|
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 3 |
Complexity Density: 0.33 |
|
234 |
2 |
public boolean clearCacheFromSkin(String skin)... |
235 |
|
{ |
236 |
2 |
XWikiContext xcontext = xcontextProvider.get(); |
237 |
|
|
238 |
|
|
239 |
2 |
if (!authorizationManager.hasAccess(Right.PROGRAM, xcontext.getDoc().getAuthorReference(), |
240 |
|
xcontext.getDoc().getDocumentReference())) { |
241 |
1 |
return false; |
242 |
|
} |
243 |
|
|
244 |
1 |
try { |
245 |
1 |
SkinReference skinReference = skinReferenceFactory.createReference(skin); |
246 |
1 |
lessCache.clearFromSkin(skinReference); |
247 |
1 |
colorThemeCache.clearFromSkin(skinReference); |
248 |
1 |
return true; |
249 |
|
} catch (LESSCompilerException e) { |
250 |
0 |
return false; |
251 |
|
} |
252 |
|
} |
253 |
|
} |