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

File AbstractCacheConfigurationLoader.java

 

Coverage histogram

../../../../img/srcFileCovDistChart7.png
64% of files have more coverage

Code metrics

8
18
5
1
120
50
9
0.5
3.6
5
1.8

Classes

Class Line # Actions
AbstractCacheConfigurationLoader 32 18 0% 9 10
0.6774193667.7%
 

Contributing tests

This file is covered by 85 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.cache.util;
21   
22    import java.io.File;
23   
24    import org.xwiki.cache.config.CacheConfiguration;
25    import org.xwiki.environment.Environment;
26   
27    /**
28    * Base class to load cache configuration.
29    *
30    * @version $Id: a0e9cb9e947f06d007199b2875454e0b83f5f7e2 $
31    */
 
32    public abstract class AbstractCacheConfigurationLoader
33    {
34    /**
35    * The name of the cache.path property in XWiki configuration.
36    */
37    private static final String CONFX_CACHE_PATH = "cache.path";
38   
39    /**
40    * The XWiki cache API configuration.
41    */
42    private CacheConfiguration configuration;
43   
44    /**
45    * The environment. Used for example to access temporary folder.
46    */
47    private Environment environment;
48   
49    /**
50    * The default configuration identifier used to load cache configuration file.
51    */
52    private String defaultPropsId;
53   
54    /**
55    * @param configuration the XWiki cache API configuration.
56    * @param defaultPropsId the default configuration identifier used to load cache configuration file.
57    */
 
58  0 toggle public AbstractCacheConfigurationLoader(CacheConfiguration configuration, String defaultPropsId)
59    {
60  0 this(configuration, null, defaultPropsId);
61    }
62   
63    /**
64    * @param configuration the XWiki cache API configuration.
65    * @param environment the environment, can be null
66    * @param defaultPropsId the default configuration identifier used to load cache configuration file.
67    */
 
68  1339 toggle public AbstractCacheConfigurationLoader(CacheConfiguration configuration, Environment environment,
69    String defaultPropsId)
70    {
71  1339 this.configuration = (CacheConfiguration) configuration.clone();
72  1339 this.environment = environment;
73  1339 this.defaultPropsId = defaultPropsId;
74    }
75   
76    /**
77    * @return the XWiki cache API configuration.
78    */
 
79  2497 toggle public CacheConfiguration getCacheConfiguration()
80    {
81  2497 return this.configuration;
82    }
83   
84    /**
85    * @return the path of the temporary local folder based on configuration identifier
86    */
 
87  32 toggle protected String createTempDir()
88    {
89  32 String path = (String) this.configuration.get(CONFX_CACHE_PATH);
90   
91  32 if (path == null) {
92  32 File file;
93  32 if (this.environment != null) {
94  32 file = new File(this.environment.getTemporaryDirectory().getAbsolutePath(), "cache");
95    } else {
96  0 file = new File(System.getProperty("java.io.tmpdir"), "xwiki");
97    }
98   
99  32 if (this.configuration.getConfigurationId() == null) {
100  0 file = new File(file, this.configuration.getConfigurationId());
101    }
102   
103  32 if (!file.exists()) {
104  32 file.mkdirs();
105    }
106   
107  32 path = file.getAbsolutePath();
108    }
109   
110  32 return path;
111    }
112   
113    /**
114    * @return the default configuration identifier used to load cache configuration file.
115    */
 
116  0 toggle public String getDefaultPropsId()
117    {
118  0 return this.defaultPropsId;
119    }
120    }