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

File XWikiPropertiesConfigurationSource.java

 

Coverage histogram

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

Code metrics

4
9
1
1
93
43
4
0.44
9
1
4

Classes

Class Line # Actions
XWikiPropertiesConfigurationSource 45 9 0% 4 1
0.928571492.9%
 

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.configuration.internal;
21   
22    import java.net.URL;
23   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26    import javax.inject.Singleton;
27   
28    import org.apache.commons.configuration.BaseConfiguration;
29    import org.apache.commons.configuration.PropertiesConfiguration;
30    import org.slf4j.Logger;
31    import org.xwiki.component.annotation.Component;
32    import org.xwiki.component.phase.Initializable;
33    import org.xwiki.component.phase.InitializationException;
34    import org.xwiki.environment.Environment;
35   
36    /**
37    * Looks for configuration data in {@code /WEB-INF/xwiki.properties}.
38    *
39    * @version $Id: 8c7372ddb9cb6affeef64a9a3f43e1589425dc0f $
40    * @since 2.0M1
41    */
42    @Component
43    @Named("xwikiproperties")
44    @Singleton
 
45    public class XWikiPropertiesConfigurationSource extends CommonsConfigurationSource implements Initializable
46    {
47    /**
48    * The file where standard filesystem properties are located.
49    */
50    private static final String XWIKI_PROPERTIES_FILE = "/WEB-INF/xwiki.properties";
51   
52    /**
53    * the Environment from where to get the XWiki properties file.
54    */
55    @Inject
56    private Environment environment;
57   
58    /**
59    * The logger to log.
60    */
61    @Inject
62    private Logger logger;
63   
 
64  61 toggle @Override
65    public void initialize() throws InitializationException
66    {
67    // Register the Commons Properties Configuration, looking for a xwiki.properties file
68    // in the XWiki path somewhere.
69  61 URL xwikiPropertiesUrl = null;
70  61 try {
71  61 xwikiPropertiesUrl = this.environment.getResource(XWIKI_PROPERTIES_FILE);
72  61 if (xwikiPropertiesUrl != null) {
73  32 setConfiguration(new PropertiesConfiguration(xwikiPropertiesUrl));
74    } else {
75    // We use a debug logging level here since we consider it's ok that there's no XWIKI_PROPERTIES_FILE
76    // available, in which case default values are used.
77  29 this.logger.debug("No configuration file [{}] found. Using default configuration values.",
78    XWIKI_PROPERTIES_FILE);
79    }
80    } catch (Exception e) {
81    // Note: if we cannot read the configuration file for any reason we log a warning but continue since XWiki
82    // will use default values for all configurable elements.
83  0 this.logger.warn("Failed to load configuration file [{}]. Using default configuration values. "
84    + "Internal error [{}]", XWIKI_PROPERTIES_FILE, e.getMessage());
85    }
86   
87    // If no Commons Properties Configuration has been set, use a default empty Commons Configuration
88    // implementation.
89  61 if (xwikiPropertiesUrl == null) {
90  29 setConfiguration(new BaseConfiguration());
91    }
92    }
93    }