|
@@ -1,13 +1,11 @@
|
|
package cn.com.qmth.examcloud.web.bootstrap;
|
|
package cn.com.qmth.examcloud.web.bootstrap;
|
|
|
|
|
|
-import java.util.Properties;
|
|
|
|
-
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
-
|
|
|
|
-import cn.com.qmth.examcloud.commons.util.PropertiesUtil;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
+import java.util.Properties;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 云配置
|
|
* 云配置
|
|
*
|
|
*
|
|
@@ -17,115 +15,105 @@ import org.slf4j.LoggerFactory;
|
|
*/
|
|
*/
|
|
public class PropertyHolder {
|
|
public class PropertyHolder {
|
|
|
|
|
|
- private static final Logger LOG = LoggerFactory.getLogger(PropertyHolder.class);
|
|
|
|
-
|
|
|
|
- private static final Properties PROPS = new Properties();
|
|
|
|
|
|
+ private static final Logger LOG = LoggerFactory.getLogger(PropertyHolder.class);
|
|
|
|
|
|
- /**
|
|
|
|
- * 从资源文件加载配置
|
|
|
|
- *
|
|
|
|
- * @author WANGWEI
|
|
|
|
- * @param resourceName
|
|
|
|
- */
|
|
|
|
- public static void loadFromResource(String resourceName) {
|
|
|
|
- PropertiesUtil.loadFromResource(resourceName, PROPS);
|
|
|
|
- }
|
|
|
|
|
|
+ private static final Properties PROPS = new Properties();
|
|
|
|
|
|
- /**
|
|
|
|
- * 设置属性
|
|
|
|
- *
|
|
|
|
- * @author WANGWEI
|
|
|
|
- * @param key
|
|
|
|
- * @param value
|
|
|
|
- */
|
|
|
|
- public static void setProperty(String key, String value) {
|
|
|
|
- PROPS.setProperty(key, value);
|
|
|
|
- }
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 设置属性
|
|
|
|
+ *
|
|
|
|
+ * @param key
|
|
|
|
+ * @param value
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ */
|
|
|
|
+ public static void setProperty(String key, String value) {
|
|
|
|
+ PROPS.setProperty(key, value);
|
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
|
- * @param key
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public static String getString(String key) {
|
|
|
|
- String value = PROPS.getProperty(key);
|
|
|
|
- if (StringUtils.isNotBlank(value)) {
|
|
|
|
- return value.trim();
|
|
|
|
- } else {
|
|
|
|
- if (LOG.isDebugEnabled()) {
|
|
|
|
- LOG.debug("No property value, key = " + key);
|
|
|
|
- }
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @param key
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static String getString(String key) {
|
|
|
|
+ String value = PROPS.getProperty(key);
|
|
|
|
+ if (StringUtils.isNotBlank(value)) {
|
|
|
|
+ return value.trim();
|
|
|
|
+ } else {
|
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
|
+ LOG.debug("No property value, key = " + key);
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
|
- * @param key
|
|
|
|
- * @param defaultValue
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public static String getString(String key, String defaultValue) {
|
|
|
|
- String value = getString(key);
|
|
|
|
- if (null != value) {
|
|
|
|
- return value;
|
|
|
|
- }
|
|
|
|
- return defaultValue;
|
|
|
|
- }
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @param key
|
|
|
|
+ * @param defaultValue
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static String getString(String key, String defaultValue) {
|
|
|
|
+ String value = getString(key);
|
|
|
|
+ if (null != value) {
|
|
|
|
+ return value;
|
|
|
|
+ }
|
|
|
|
+ return defaultValue;
|
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
|
- * @param key
|
|
|
|
- * @param defaultValue
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public static int getInt(String key, int defaultValue) {
|
|
|
|
- String value = getString(key);
|
|
|
|
- if (null != value) {
|
|
|
|
- try {
|
|
|
|
- return Integer.parseInt(value);
|
|
|
|
- } catch (NumberFormatException e) {
|
|
|
|
- PROPS.setProperty(key, String.valueOf(defaultValue));
|
|
|
|
- return defaultValue;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return defaultValue;
|
|
|
|
- }
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @param key
|
|
|
|
+ * @param defaultValue
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static int getInt(String key, int defaultValue) {
|
|
|
|
+ String value = getString(key);
|
|
|
|
+ if (null != value) {
|
|
|
|
+ try {
|
|
|
|
+ return Integer.parseInt(value);
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
+ PROPS.setProperty(key, String.valueOf(defaultValue));
|
|
|
|
+ return defaultValue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return defaultValue;
|
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
|
- * @param key
|
|
|
|
- * @param defaultValue
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public static long getLong(String key, long defaultValue) {
|
|
|
|
- String value = getString(key);
|
|
|
|
- if (null != value) {
|
|
|
|
- try {
|
|
|
|
- return Long.parseLong(value);
|
|
|
|
- } catch (NumberFormatException e) {
|
|
|
|
- return defaultValue;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return defaultValue;
|
|
|
|
- }
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @param key
|
|
|
|
+ * @param defaultValue
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static long getLong(String key, long defaultValue) {
|
|
|
|
+ String value = getString(key);
|
|
|
|
+ if (null != value) {
|
|
|
|
+ try {
|
|
|
|
+ return Long.parseLong(value);
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
+ return defaultValue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return defaultValue;
|
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
|
- * 获取boolean
|
|
|
|
- *
|
|
|
|
- * @author WANGWEI
|
|
|
|
- * @param key
|
|
|
|
- * @param defaultVale
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public static boolean getBoolean(String key, boolean defaultVale) {
|
|
|
|
- String value = getString(key);
|
|
|
|
- if (null == value) {
|
|
|
|
- return defaultVale;
|
|
|
|
- }
|
|
|
|
- if (value.equals("true")) {
|
|
|
|
- return true;
|
|
|
|
- } else if (value.equals("false")) {
|
|
|
|
- return false;
|
|
|
|
- } else {
|
|
|
|
- return defaultVale;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 获取boolean
|
|
|
|
+ *
|
|
|
|
+ * @param key
|
|
|
|
+ * @param defaultVale
|
|
|
|
+ * @return
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ */
|
|
|
|
+ public static boolean getBoolean(String key, boolean defaultVale) {
|
|
|
|
+ String value = getString(key);
|
|
|
|
+ if (null == value) {
|
|
|
|
+ return defaultVale;
|
|
|
|
+ }
|
|
|
|
+ if (value.equals("true")) {
|
|
|
|
+ return true;
|
|
|
|
+ } else if (value.equals("false")) {
|
|
|
|
+ return false;
|
|
|
|
+ } else {
|
|
|
|
+ return defaultVale;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|