From fdbc8ca146b8e3aff0425e2faf94c0b4a6e3dd28 Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Tue, 18 Nov 2014 20:07:36 +0000
Subject: [PATCH] #396 fix - Corrected cancel action and added Settings entity

---
 securis/src/main/java/net/curisit/securis/utils/Config.java |  303 ++++++++++++++++++++++++++------------------------
 1 files changed, 157 insertions(+), 146 deletions(-)

diff --git a/securis/src/main/java/net/curisit/securis/utils/Config.java b/securis/src/main/java/net/curisit/securis/utils/Config.java
index bd22171..1d43249 100644
--- a/securis/src/main/java/net/curisit/securis/utils/Config.java
+++ b/securis/src/main/java/net/curisit/securis/utils/Config.java
@@ -17,182 +17,193 @@
  */
 public class Config {
 
-	private static final Logger LOG = LogManager.getLogger(Config.class);
+    private static final Logger LOG = LogManager.getLogger(Config.class);
 
-	/**
-	 * Key used to store config file resource location. In a web application, can be set as initial parameter in a servlet loaded on startup
-	 */
-	public static final String KEY_CONFIG_FILE = "/securis-server.properties";
+    /**
+     * Key used to store config file resource location. In a web application,
+     * can be set as initial parameter in a servlet loaded on startup
+     */
+    public static final String KEY_CONFIG_FILE = "/securis-server.properties";
 
-	private static Properties params = null;
+    private static Properties params = null;
 
-	static {
-		try {
-			loadParameters(KEY_CONFIG_FILE);
-		} catch (IOException e) {
-			LOG.error("Config file {} was not found in classpath", KEY_CONFIG_FILE);
-			System.exit(-2);
-		}
-	}
+    static {
+        try {
+            loadParameters(KEY_CONFIG_FILE);
+        } catch (IOException e) {
+            LOG.error("Config file {} was not found in classpath", KEY_CONFIG_FILE);
+            System.exit(-2);
+        }
+    }
 
-	/**
-	 * Loads application global parameters from a classpath resource
-	 * 
-	 * @param resource
-	 *            : Resource location in classpath, i.e: "/resource/cp-securis.conf"
-	 * @throws IOException
-	 */
-	public static void loadParameters(String resource) throws IOException {
+    /**
+     * Loads application global parameters from a classpath resource
+     * 
+     * @param resource
+     *            : Resource location in classpath, i.e:
+     *            "/resource/cp-securis.conf"
+     * @throws IOException
+     */
+    public static void loadParameters(String resource) throws IOException {
 
-		LOG.debug("Loading params from " + resource);
-		InputStream fileis = Params.class.getResourceAsStream(resource);
+        LOG.debug("Loading params from " + resource);
+        InputStream fileis = Params.class.getResourceAsStream(resource);
 
-		params = new Properties();
-		try {
+        params = new Properties();
+        try {
 
-			params.load(fileis);
-			LOG.debug("Params loaded OK from {}", resource);
-		} catch (IOException e) {
-			LOG.error("Error loading config file: " + e);
-			params = null;
-			throw e;
-		}
+            params.load(fileis);
+            LOG.debug("Params loaded OK from {}", resource);
+        } catch (IOException e) {
+            LOG.error("Error loading config file: " + e);
+            params = null;
+            throw e;
+        }
 
-	}
+    }
 
-	public static String getByDomain(String domain, String paramname) {
-		return getByDomain(domain, paramname, null);
-	}
+    public static String getByDomain(String domain, String paramname) {
+        return getByDomain(domain, paramname, null);
+    }
 
-	public static String getByPrefix(String prefix, String paramname) {
-		return get(prefix + "." + paramname, get(paramname));
-	}
+    public static String getByPrefix(String prefix, String paramname) {
+        return get(prefix + "." + paramname, get(paramname));
+    }
 
-	public static String getByPrefix(String prefix, String paramname, String defaultVal) {
-		return get(prefix + "." + paramname, get(paramname, defaultVal));
-	}
+    public static String getByPrefix(String prefix, String paramname, String defaultVal) {
+        return get(prefix + "." + paramname, get(paramname, defaultVal));
+    }
 
-	public static String getByDomain(String domain, String paramname, String defaultval) {
-		return get(paramname + "." + domain, defaultval);
-	}
+    public static String getByDomain(String domain, String paramname, String defaultval) {
+        return get(paramname + "." + domain, defaultval);
+    }
 
-	public static int getIntByDomain(String domain, String paramname) {
-		return getInt(paramname + "." + domain, getInt(paramname));
-	}
+    public static int getIntByDomain(String domain, String paramname) {
+        return getInt(paramname + "." + domain, getInt(paramname));
+    }
 
-	public static int getIntByDomain(String domain, String paramname, int defaultval) {
-		return getInt(paramname + "." + domain, defaultval);
-	}
+    public static int getIntByDomain(String domain, String paramname, int defaultval) {
+        return getInt(paramname + "." + domain, defaultval);
+    }
 
-	/**
-	 * Gets a List with all values of properties that begins with <code>prefix</code> It reads sequentially. For example:
-	 * 
-	 * <pre>
-	 * 	securis.sort.comparator.0: net.cp.securis.comparators.ComparePttidVsPtn
-	 * 	securis.sort.comparator.1: net.cp.securis.comparators.CompareFrequency
-	 * 	securis.sort.comparator.2: net.cp.securis.comparators.CompareOutgoingVsIncomming
-	 * 	securis.sort.comparator.3: net.cp.securis.comparators.CompareDuration 
-	 * 	securis.sort.comparator.4: net.cp.securis.comparators.CompareCallVsSms
-	 * </pre>
-	 * 
-	 * That config (for prefix: "securis.sort.comparator" ) will return a List<String> with values:
-	 * 
-	 * <pre>
-	 * 	"net.cp.securis.comparators.ComparePttidVsPtn", 
-	 * 	"net.cp.securis.comparators.CompareFrequency", 
-	 * 	"net.cp.securis.comparators.CompareOutgoingVsIncomming", 
-	 * 	"net.cp.securis.comparators.CompareDuration", 
-	 * 	"net.cp.securis.comparators.CompareCallVsSms"
-	 * </pre>
-	 * 
-	 * Note: If there is a gap between suffixes process will stop, that is, only will be returned properties found before gap.
-	 * 
-	 * @param prefix
-	 * @return
-	 */
-	public static List<String> getListByPrefix(String prefix) {
-		List<String> list = new ArrayList<String>();
+    /**
+     * Gets a List with all values of properties that begins with
+     * <code>prefix</code> It reads sequentially. For example:
+     * 
+     * <pre>
+     * 	securis.sort.comparator.0: net.cp.securis.comparators.ComparePttidVsPtn
+     * 	securis.sort.comparator.1: net.cp.securis.comparators.CompareFrequency
+     * 	securis.sort.comparator.2: net.cp.securis.comparators.CompareOutgoingVsIncomming
+     * 	securis.sort.comparator.3: net.cp.securis.comparators.CompareDuration 
+     * 	securis.sort.comparator.4: net.cp.securis.comparators.CompareCallVsSms
+     * </pre>
+     * 
+     * That config (for prefix: "securis.sort.comparator" ) will return a
+     * List<String> with values:
+     * 
+     * <pre>
+     * 	"net.cp.securis.comparators.ComparePttidVsPtn", 
+     * 	"net.cp.securis.comparators.CompareFrequency", 
+     * 	"net.cp.securis.comparators.CompareOutgoingVsIncomming", 
+     * 	"net.cp.securis.comparators.CompareDuration", 
+     * 	"net.cp.securis.comparators.CompareCallVsSms"
+     * </pre>
+     * 
+     * Note: If there is a gap between suffixes process will stop, that is, only
+     * will be returned properties found before gap.
+     * 
+     * @param prefix
+     * @return
+     */
+    public static List<String> getListByPrefix(String prefix) {
+        List<String> list = new ArrayList<String>();
 
-		String tpl = prefix + ".{0}";
+        String tpl = prefix + ".{0}";
 
-		int i = 0;
-		String value = get(MessageFormat.format(tpl, i++));
-		while (value != null) {
-			list.add(value);
-			value = get(MessageFormat.format(tpl, i++));
-		}
+        int i = 0;
+        String value = get(MessageFormat.format(tpl, i++));
+        while (value != null) {
+            list.add(value);
+            value = get(MessageFormat.format(tpl, i++));
+        }
 
-		return list;
-	}
+        return list;
+    }
 
-	/**
-	 * Gets param value in config file or environment variables
-	 * 
-	 * @param paramname
-	 *            Global parameter's name
-	 * @return Value of paramname or null if paramname is not found neither in config file nor in environment variables
-	 */
-	public static String get(String paramname) {
+    /**
+     * Gets param value in config file or environment variables
+     * 
+     * @param paramname
+     *            Global parameter's name
+     * @return Value of paramname or null if paramname is not found neither in
+     *         config file nor in environment variables
+     */
+    public static String get(String paramname) {
 
-		assert (params != null) : "Parameters have not been loaded. Call method loadParameters(resource) before use Params.";
+        assert (params != null) : "Parameters have not been loaded. Call method loadParameters(resource) before use Params.";
 
-		String value = params.getProperty(paramname);
-		if (value == null)
-			value = System.getenv(paramname);
-		return value;
-	}
+        String value = params.getProperty(paramname);
+        if (value == null)
+            value = System.getenv(paramname);
+        return value;
+    }
 
-	/**
-	 * Gets param value from config file or environment variables
-	 * 
-	 * @param paramname
-	 *            Global parameter's name
-	 * @param defaultval
-	 * @return Value of paramname or defaultval if paramname is not found
-	 */
-	public static String get(String paramname, String defaultval) {
-		String value = get(paramname);
-		return (value == null ? defaultval : value);
-	}
+    /**
+     * Gets param value from config file or environment variables
+     * 
+     * @param paramname
+     *            Global parameter's name
+     * @param defaultval
+     * @return Value of paramname or defaultval if paramname is not found
+     */
+    public static String get(String paramname, String defaultval) {
+        String value = get(paramname);
+        return (value == null ? defaultval : value);
+    }
 
-	/**
-	 * Gets param value in config file or environment variables
-	 * 
-	 * @param paramname
-	 *            Global parameter's name
-	 * @return Integer value of paramname or -1 if paramname is not found neither in config file nor in environment variables
-	 */
-	public static int getInt(String paramname) {
-		String value = get(paramname);
-		return (value == null ? -1 : Integer.parseInt(value));
-	}
+    /**
+     * Gets param value in config file or environment variables
+     * 
+     * @param paramname
+     *            Global parameter's name
+     * @return Integer value of paramname or -1 if paramname is not found
+     *         neither in config file nor in environment variables
+     */
+    public static int getInt(String paramname) {
+        String value = get(paramname);
+        return (value == null ? -1 : Integer.parseInt(value));
+    }
 
-	/**
-	 * Gets param value from config file or environment variables
-	 * 
-	 * @param paramname
-	 *            Global parameter's name
-	 * @param defaultval
-	 * @return Integer value of paramname or defaultval if paramname is not found
-	 */
-	public static int getInt(String paramname, int defaultval) {
-		String value = get(paramname);
-		return (value == null ? defaultval : Integer.parseInt(value));
-	}
+    /**
+     * Gets param value from config file or environment variables
+     * 
+     * @param paramname
+     *            Global parameter's name
+     * @param defaultval
+     * @return Integer value of paramname or defaultval if paramname is not
+     *         found
+     */
+    public static int getInt(String paramname, int defaultval) {
+        String value = get(paramname);
+        return (value == null ? defaultval : Integer.parseInt(value));
+    }
 
-	public static class KEYS {
+    public static class KEYS {
 
+        public static final String SERVER_HOSTNAME = "license.server.hostname";
 
-	            
-		public static final String SERVER_HOSTNAME = "license.server.hostname";
+        public static final String SERVER_PORT = "license.server.port";
+        public static final String SERVER_SSL_PORT = "license.server.ssl.port";
 
-	    public static final String SERVER_PORT = "license.server.port";
-	    public static final String SERVER_SSL_PORT = "license.server.ssl.port";
-
-		public static final String KEYSTORE_PATH = "ssl.keystore.path";
+        public static final String KEYSTORE_PATH = "ssl.keystore.path";
         public static final String KEYSTORE_TYPE = "ssl.keystore.type";
         public static final String KEYSTORE_PASSWORD = "ssl.keystore.password";
         public static final String KEYSTORE_ALIAS = "ssl.keystore.alias";
-	}
+
+        public static final String MAILGUN_DOMAIN = "mailgun.domain";
+        public static final String MAILGUN_API_KEY = "mailgun.api.key";
+        public static final String EMAIL_FROM_ADDRESS = "email.from.address";
+        public static final String EMAIL_LIC_DEFAULT_SUBJECT = "email.lic.default.subject";
+    }
 
 }

--
Gitblit v1.3.2