
io.konik.Configuration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of konik Show documentation
Show all versions of konik Show documentation
Konik the ZUGFeRD processing library
The newest version!
/* Copyright (C) 2014 konik.io
*
* This file is part of the Konik library.
*
* The Konik library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* The Konik library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with the Konik library. If not, see .
*/
package io.konik;
import static java.util.logging.Level.CONFIG;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.logging.Logger;
/**
* The Global Konik Configuration.
*
* Try to load Konik Configuration from file `io.konik.configuration.properties`.
* System properties provided with the +-Dio.konik*+ or ```System.setProperties("io.konik*")`` will override the file
* content.
*
*/
public enum Configuration {
/** The singleton configuration instance. */
INSTANCE;
private static final Logger LOG = Logger.getLogger(Configuration.class.getName());
private final Properties properties;
Configuration() {
properties = new Properties();
loadPropertiesFromFile();
overwriteWithSystemProperties();
}
void reload() {
loadPropertiesFromFile();
overwriteWithSystemProperties();
}
private void loadPropertiesFromFile() {
String fileName = Configuration.class.getName().toLowerCase();
InputStream propertiesStream = this.getClass().getResourceAsStream("/" + fileName + ".properties");
if (propertiesStream != null) {
try {
properties.load(propertiesStream);
} catch (IOException e) {
LOG.log(CONFIG, "could not load properties file" + fileName + " from classpath", e);
}
}
}
private void overwriteWithSystemProperties() {
for (Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy