Load configuration from ddf.ini, or the file name specified by the environment variable DDF_INI. @return the Configuration object loaded @throws Exception @throws ConfigurationException , IOException
()
| 149 | * @throws ConfigurationException , {@link IOException} |
| 150 | */ |
| 151 | @Override |
| 152 | public Configuration loadConfig() throws ConfigurationException, IOException { |
| 153 | |
| 154 | Configuration resultConfig = new Configuration(); |
| 155 | |
| 156 | if (!Utils.localFileExists(this.getConfigFileName())) { |
| 157 | // String configFileName = System.getenv(ConfigConstant.DDF_INI_ENV_VAR.getValue()); |
| 158 | File file = new File(this.locateConfigFileName(this.getConfigDir(), this.getConfigFileName())); |
| 159 | mConfigDir = file.getParentFile().getName(); |
| 160 | mConfigFileName = file.getCanonicalPath(); |
| 161 | } |
| 162 | |
| 163 | if (!Utils.localFileExists(this.getConfigFileName())) return null; |
| 164 | |
| 165 | HierarchicalINIConfiguration config = new HierarchicalINIConfiguration(this.getConfigFileName()); |
| 166 | |
| 167 | @SuppressWarnings("unchecked") |
| 168 | Set<String> sectionNames = config.getSections(); |
| 169 | for (String sectionName : sectionNames) { |
| 170 | SubnodeConfiguration section = config.getSection(sectionName); |
| 171 | if (section != null) { |
| 172 | Configuration.Section resultSection = resultConfig.getSection(sectionName); |
| 173 | |
| 174 | @SuppressWarnings("unchecked") |
| 175 | Iterator<String> keys = section.getKeys(); |
| 176 | while (keys.hasNext()) { |
| 177 | String key = keys.next(); |
| 178 | String value = section.getString(key); |
| 179 | if (value != null) { |
| 180 | resultSection.set(key, value); |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | mConfig = resultConfig; |
| 187 | return mConfig; |
| 188 | } |
| 189 | |
| 190 | @Override |
| 191 | public void setConfig(Configuration theConfig) { |
no test coverage detected