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.converter; |
21 |
|
|
22 |
|
import java.util.regex.Matcher; |
23 |
|
import java.util.regex.Pattern; |
24 |
|
|
25 |
|
import javax.inject.Inject; |
26 |
|
import javax.inject.Singleton; |
27 |
|
|
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.colortheme.ColorTheme; |
32 |
|
import org.xwiki.lesscss.resources.LESSResourceReference; |
33 |
|
import org.xwiki.lesscss.internal.cache.CachedCompilerInterface; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
@since |
39 |
|
@version |
40 |
|
|
41 |
|
@Component(roles = CachedLESSColorThemeConverter.class) |
42 |
|
@Singleton |
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
43 |
|
public class CachedLESSColorThemeConverter implements CachedCompilerInterface<ColorTheme> |
44 |
|
{ |
45 |
|
@Inject |
46 |
|
private LESSCompiler lessCompiler; |
47 |
|
|
48 |
|
private final Pattern pattern = Pattern.compile("\\.colortheme-(\\w+)[\\s$]*\\{(\\w+):(#*\\w+)(;)*\\}"); |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
50 |
35 |
@Override... |
51 |
|
public ColorTheme compute(LESSResourceReference lessResourceReference, boolean includeSkinStyle, |
52 |
|
boolean useVelocity, boolean useLESS, String skin) |
53 |
|
throws LESSCompilerException |
54 |
|
{ |
55 |
35 |
return getColorThemeFromCSS(lessCompiler.compile(lessResourceReference, false, useVelocity, skin, false)); |
56 |
|
} |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
@param |
61 |
|
@return |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
63 |
35 |
private ColorTheme getColorThemeFromCSS(String css)... |
64 |
|
{ |
65 |
35 |
ColorTheme results = new ColorTheme(); |
66 |
35 |
String cssWithoutComments = css.replaceAll("/\\*[\\u0000-\\uffff]*?\\*/", ""); |
67 |
35 |
Matcher m = pattern.matcher(cssWithoutComments); |
68 |
819 |
while (m.find()) { |
69 |
784 |
String variable = m.group(1); |
70 |
784 |
String value = m.group(3); |
71 |
784 |
results.put(variable, value); |
72 |
|
} |
73 |
35 |
return results; |
74 |
|
} |
75 |
|
} |