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

File LESSSkinFileResourceReference.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

4
15
6
1
97
54
9
0.6
2.5
6
1.5

Classes

Class Line # Actions
LESSSkinFileResourceReference 34 15 0% 9 4
0.8484%
 

Contributing tests

This file is covered by 11 tests. .

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.resources;
21   
22    import org.xwiki.lesscss.compiler.LESSCompilerException;
23    import org.xwiki.lesscss.resources.LESSResourceReference;
24    import org.xwiki.skin.SkinManager;
25    import org.xwiki.template.Template;
26    import org.xwiki.template.TemplateManager;
27   
28    /**
29    * A reference to a skin file located in the "less" directory.
30    *
31    * @since 6.4M2
32    * @version $Id :$
33    */
 
34    public class LESSSkinFileResourceReference implements LESSResourceReference
35    {
36    private String fileName;
37   
38    private TemplateManager templateManager;
39   
40    private SkinManager skinManager;
41   
42    /**
43    * Constructor.
44    * @param fileName name of the file inside the "less" directory in the skin
45    * @param templateManager component to get templates
46    * @param skinManager component to get skins
47    */
 
48  2161 toggle public LESSSkinFileResourceReference(String fileName, TemplateManager templateManager, SkinManager skinManager)
49    {
50  2161 this.fileName = fileName;
51  2160 this.templateManager = templateManager;
52  2162 this.skinManager = skinManager;
53    }
54   
 
55  48 toggle @Override
56    public boolean equals(Object o)
57    {
58  48 if (o instanceof LESSSkinFileResourceReference) {
59  48 return fileName.equals(((LESSSkinFileResourceReference) o).fileName);
60    }
61   
62  0 return false;
63    }
64   
 
65  148 toggle @Override
66    public int hashCode()
67    {
68  148 return fileName.hashCode();
69    }
70   
 
71  37 toggle @Override public String getContent(String skin) throws LESSCompilerException
72    {
73  37 Template template = templateManager.getTemplate("less/" + fileName, skinManager.getSkin(skin));
74  37 if (template == null) {
75  1 throw new LESSCompilerException(String.format("The template [%s] does not exists.", fileName));
76    }
77   
78  36 try {
79  36 return template.getContent().getContent();
80    } catch (Exception e) {
81  1 throw new LESSCompilerException(
82    String.format("Failed to get the content of the template [%s].", fileName), e);
83    }
84    }
85   
 
86  4391 toggle @Override
87    public String serialize()
88    {
89  4393 return String.format("LessSkinFile[%s]", fileName);
90    }
91   
 
92  0 toggle @Override
93    public String toString()
94    {
95  0 return serialize();
96    }
97    }