com.lone.common.util.file.PropertiesHolder Maven / Gradle / Ivy
The newest version!
package com.lone.common.util.file;
import java.io.IOException;
import java.util.Properties;
import org.springframework.core.io.ClassPathResource;
import com.lone.common.util.StringUtil;
/**
*
*
*
*/
public class PropertiesHolder {
/** weixin.properties初始化 */
private static Properties prosWeixin = null;
/** sysConfig.properties初始化 */
private static Properties prosConfig = null;
/** lang_zh-cn.properties初始化 */
private static Properties prosLang = null;
/** lang_sdis_zh-cn.properties初始化 */
private static Properties prosLangKey = null;
/** oracle-sql.properties初始化 */
private static Properties prosSQL = null;
/**
* lang_zh-cn.properties初始化
*/
public static void initLangFile() {
if (prosLang == null) {
prosLang = new Properties();
ClassPathResource cr = new ClassPathResource("lang/lang_zh-cn.properties");
try {
prosLang.load(cr.getInputStream());
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
/**
* lang_zh-cn.properties初始化
*/
public static void initLangKeyFile(boolean force, String key) {
if (prosLangKey == null || force) {
prosLangKey = new Properties();
ClassPathResource cr = null;
if (!StringUtil.isEmpty(key)) {
cr = new ClassPathResource("lang/lang_" + key + "_zh-cn.properties");
} else {
cr = new ClassPathResource("lang/lang_zh-cn.properties");
}
try {
prosLangKey.load(cr.getInputStream());
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
/**
* weixin.properties初始化
*/
public static void initWeixinFile() {
if (prosWeixin == null) {
prosWeixin = new Properties();
ClassPathResource cr = new ClassPathResource("weixin/weixin.properties");
try {
prosWeixin.load(cr.getInputStream());
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
/**
* sysConfig.properties初始化
*/
public static void initConfigFile() {
if (prosConfig == null) {
prosConfig = new Properties();
ClassPathResource cr = new ClassPathResource("sysConfig.properties");
try {
prosConfig.load(cr.getInputStream());
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
/**
* oracle-sql.properties初始化
*/
public static void initSqlFile() {
if (prosSQL == null) {
prosSQL = new Properties();
String dialect = PropertiesHolder.getSqlValue("jdbc.dialect");
String propName = "db/" + dialect + "-sql.properties";
ClassPathResource cr = new ClassPathResource(propName);
try {
prosSQL.load(cr.getInputStream());
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
/**
* 获取Lang文件的key值
* @param key
* @return
*/
public static String getLangValue(String key) {
initLangFile();
String value = prosLang.getProperty(key);
return value;
}
/**
* 获取LangSdis文件的key值
* @param key
* @return
*/
public static String getLangValueByKey(String langFile, String key) {
initLangKeyFile(true, langFile);
String value = prosLangKey.getProperty(key);
return value;
}
/**
* 获取DAO文件的key值
* @param key
* @return
*/
public static String getWeixinValue(String key) {
initWeixinFile();
String value = prosWeixin.getProperty(key);
return value;
}
/**
* 获取Config文件的key值
* @param key
* @return
*/
public static String getConfValue(String key) {
initConfigFile();
String value = prosConfig.getProperty(key);
return value;
}
/**
* 获取sql文件的key值
* @param key
* @return
*/
public static String getSqlValue(String key) {
initSqlFile();
String value = prosSQL.getProperty(key);
return value;
}
}