1 /*
2 * This file is part of AceLogger.
3 *
4 * AceLogger is free software: you can redistribute it and/or modify it under the terms of the GNU
5 * Lesser General Public License as published by the Free Software Foundation, either version 3 of
6 * the License, or (at your option) any later version.
7 *
8 * AceLogger is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
9 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public License along with AceLogger.
13 * If not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
14 */
15 package net.sourceforge.acelogger.configuration.parser;
16
17 import java.io.IOException;
18 import java.io.InputStream;
19 import java.util.Properties;
20 import java.util.Map.Entry;
21
22 import net.sourceforge.acelogger.configuration.BaseConfigurationLoader;
23 import net.sourceforge.acelogger.execution.LogController;
24
25 /**
26 * An implementation of configuration loader that uses java properties files as source for
27 * configuration.
28 *
29 * @author Zardi (https://sourceforge.net/users/daniel_zardi)
30 * @version 1.0.0
31 * @since 1.0.0
32 */
33 public class PropertiesConfigurationLoader extends BaseConfigurationLoader {
34
35 /** {@inheritDoc} */
36 public void configureFrom(InputStream source) {
37 Properties configurationProperties = new Properties();
38 try {
39 configurationProperties.load(source);
40 for (Entry<Object, Object> currentEntry : configurationProperties.entrySet()) {
41 if (String.class.isAssignableFrom(currentEntry.getKey().getClass())) {
42 String keyName = currentEntry.getKey().toString();
43 /*
44 * TODO: Create an Enum for every configuration option (logger, appender, etc)
45 * and the corresponding regular expression. Test the key using the expressions
46 * to determine the type and then use the enum in a switch to do the work.
47 */
48 } else {
49 LogController.getInternalLogger().error(
50 "This Loader supports only strings as keys, but a an"
51 + " instance of {0} was received", currentEntry.getClass()
52 );
53 }
54 }
55 source.close();
56 } catch (IOException e) {
57 LogController.getInternalLogger().error("Stream error during configuration", e);
58 }
59 }
60
61 }