package at.gv.egiz.simpleSigning.cfg; import java.io.FileInputStream; import java.util.Properties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class Configuration { public static final String CONF_FILE = "simpleSign.config"; public static final String PUBLIC_HOST = "publichost"; public static final String PUBLIC_CONTEXT = "publiccontext"; public static final String PDF_AS_LOCATION = "pdfasurl"; public static final String LOG4J_FILE = "log4j"; private static final Logger logger = LoggerFactory.getLogger(Configuration.class); private static Properties properties = new Properties(); public static void configure() { String config = System.getProperty(CONF_FILE); if(config == null) { logger.error("No web configuration provided! Please specify: " + CONF_FILE); throw new RuntimeException("No web configuration provided! Please specify: " + CONF_FILE); } properties.clear(); try { properties.load(new FileInputStream(config)); } catch (Exception e) { logger.error("Failed to load configuration: " + e.getMessage()); throw new RuntimeException(e); } } private static String getStringValue(String configKey, String defaultValue) { String value = properties.getProperty(configKey); if(value == null) { value = defaultValue; } return value; } public static String getPublicHost() { return getStringValue(PUBLIC_HOST, "http://demo.egiz.gv.at"); } public static String getPublicContext() { return getStringValue(PUBLIC_CONTEXT, "/signSimple"); } public static String getPublicUrl() { return getPublicHost() + getPublicContext(); } public static String getPDFAsLocation() { return getStringValue(PDF_AS_LOCATION, "http://demo.egiz.gv.at/pdf-as-web"); } public static String getLog4J() { return getStringValue(LOG4J_FILE, "log4j.properties"); } }