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

File LESSContext.java

 

Coverage histogram

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

Code metrics

2
10
7
1
100
48
8
0.8
1.43
7
1.14

Classes

Class Line # Actions
LESSContext 37 10 0% 8 0
1.0100%
 

Contributing tests

This file is covered by 4 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;
21   
22    import javax.inject.Inject;
23    import javax.inject.Singleton;
24   
25    import org.xwiki.component.annotation.Component;
26    import org.xwiki.context.Execution;
27    import org.xwiki.context.ExecutionContext;
28   
29    /**
30    * Store and get LESS configuration variables from the execution context of the request.
31    *
32    * @version $Id: 38b38485b5c726d2d5f74e54ebc30ec03fb04bef $
33    * @since 6.4
34    */
35    @Component(roles = LESSContext.class)
36    @Singleton
 
37    public class LESSContext
38    {
39    private static final String CACHE_PROPERTY = "less.cache.disable";
40   
41    private static final String HTML_EXPORT = "less.htmlexport";
42   
43    @Inject
44    private Execution execution;
45   
46    /**
47    * Disable the LESS cache.
48    */
 
49  3 toggle public void disableCache()
50    {
51  3 setProperty(CACHE_PROPERTY, true);
52    }
53   
54    /**
55    * Stop disabling the LESS cache.
56    */
 
57  2 toggle public void stopDisablingCache()
58    {
59  2 setProperty(CACHE_PROPERTY, false);
60    }
61   
62    /**
63    * @return if the cache is disabled
64    */
 
65  2166 toggle public boolean isCacheDisabled()
66    {
67  2166 return Boolean.TRUE.equals(getContext().getProperty(CACHE_PROPERTY));
68    }
69   
70    /**
71    * @param htmlExport whether or not XWiki is performing an HTML export.
72    */
 
73  2 toggle public void setHtmlExport(boolean htmlExport)
74    {
75  2 setProperty(HTML_EXPORT, htmlExport);
76    }
77   
78    /**
79    * @return whether or not XWiki is performing an HTML export.
80    */
 
81  2097 toggle public boolean isHtmlExport()
82    {
83  2097 return Boolean.TRUE.equals(getContext().getProperty(HTML_EXPORT));
84    }
85   
 
86  4273 toggle private ExecutionContext getContext()
87    {
88  4273 return execution.getContext();
89    }
90   
 
91  7 toggle private void setProperty(String propertyName, Object value)
92    {
93  7 Object property = getContext().getProperty(propertyName);
94  7 if (property != null) {
95  3 getContext().setProperty(propertyName, value);
96    } else {
97  4 getContext().newProperty(propertyName).inherited().initial(value).declare();
98    }
99    }
100    }