1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.lesscss.internal.colortheme.converter

File CachedLESSColorThemeConverter.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

2
9
2
1
75
38
3
0.33
4.5
2
1.5

Classes

Class Line # Actions
CachedLESSColorThemeConverter 43 9 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * Computes a color theme corresponding to a LESS file. To be used with AbstractCachedCompiler.
37    *
38    * @since 7.0RC1
39    * @version $Id: 9f65d03463d497c3234097a1131aa0a3725f1804 $
40    */
41    @Component(roles = CachedLESSColorThemeConverter.class)
42    @Singleton
 
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   
 
50  35 toggle @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    * Parse a CSS and returns a Color Theme.
60    * @param css code to parse
61    * @return the corresponding color theme
62    */
 
63  35 toggle 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    }