1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki

File XWikiConfig.java

 

Coverage histogram

../../../img/srcFileCovDistChart6.png
69% of files have more coverage

Code metrics

2
16
7
1
115
61
10
0.62
2.29
7
1.43

Classes

Class Line # Actions
XWikiConfig 37 16 0% 10 11
0.5656%
 

Contributing tests

This file is covered by 9 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 com.xpn.xwiki;
21   
22    import java.io.FileInputStream;
23    import java.io.FileNotFoundException;
24    import java.io.IOException;
25    import java.io.InputStream;
26    import java.util.Properties;
27   
28    import org.apache.commons.io.IOUtils;
29    import org.apache.commons.lang3.StringUtils;
30   
31    import com.xpn.xwiki.internal.XWikiCfgConfigurationSource;
32   
33    /**
34    * @deprecated since 6.1M2, use {@link XWikiCfgConfigurationSource} component instead
35    */
36    @Deprecated
 
37    public class XWikiConfig extends Properties
38    {
 
39  17343 toggle public XWikiConfig()
40    {
41    // Default constructor so that properties can be added after constructing the instance
42    // by using XWikiConfig.put().
43    }
44   
 
45  0 toggle public XWikiConfig(String path) throws XWikiException
46    {
47  0 try {
48  0 FileInputStream fis = new FileInputStream(path);
49  0 try {
50  0 loadConfig(fis, path);
51    } finally {
52  0 IOUtils.closeQuietly(fis);
53    }
54    } catch (FileNotFoundException e) {
55  0 Object[] args = { path };
56  0 throw new XWikiException(XWikiException.MODULE_XWIKI_CONFIG,
57    XWikiException.ERROR_XWIKI_CONFIG_FILENOTFOUND, "Configuration file {0} not found", e, args);
58    }
59    }
60   
 
61  30 toggle public XWikiConfig(InputStream is) throws XWikiException
62    {
63  30 if (is != null) {
64  30 loadConfig(is, "");
65    }
66    }
67   
 
68  30 toggle public void loadConfig(InputStream is, String path) throws XWikiException
69    {
70  30 try {
71  30 load(is);
72    } catch (IOException e) {
73  0 Object[] args = { path };
74  0 throw new XWikiException(XWikiException.MODULE_XWIKI_CONFIG, XWikiException.ERROR_XWIKI_CONFIG_FORMATERROR,
75    "Error reading configuration file", e, args);
76    }
77    }
78   
79    /**
80    * @return array of string splited from property.
81    * @param param - name of property
82    */
 
83  212 toggle public String[] getPropertyAsList(String param)
84    {
85  212 return StringUtils.split(getProperty(param, ""), " ,");
86    }
87   
88    /**
89    * {@inheritDoc}
90    * <p>
91    * This method trims the spaces around the value.
92    * </p>
93    *
94    * @see java.util.Properties#getProperty(java.lang.String, java.lang.String)
95    */
 
96  13 toggle @Override
97    public String getProperty(String key, String defaultValue)
98    {
99  13 return StringUtils.trim(super.getProperty(key, defaultValue));
100    }
101   
102    /**
103    * {@inheritDoc}
104    * <p>
105    * This method trims the spaces around the value.
106    * </p>
107    *
108    * @see java.util.Properties#getProperty(java.lang.String)
109    */
 
110  69959 toggle @Override
111    public String getProperty(String key)
112    {
113  69959 return StringUtils.trim(super.getProperty(key));
114    }
115    }