/** * */ package com.yihu.base; import java.io.InputStream; import org.dom4j.Document; import org.dom4j.io.SAXReader; import com.yihu.utils.SecretUtil; /** * 获取sys.xml配置 */ public class ConfigUtil { private static ConfigUtil instance = null; private static final String cfg = "sys.xml"; private String secret;// 秘钥 private String openPlatformUrl;// 开放平台接口网址 private String centerServerUrl; private String appId; private String netWork; private String appName; private String esUrl; public String getSecret() { return secret; } public String getOpenPlatformUrl() { return openPlatformUrl; } public String getCenterServerUrl() { return centerServerUrl; } public String getAppId() { return appId; } public void setAppId(String appId) { this.appId = appId; } public String getNetWork() { return netWork; } public void setNetWork(String netWork) { this.netWork = netWork; } public String getAppName() { return appName; } public String getEsUrl() { return esUrl; } public void setEsUrl(String esUrl) { this.esUrl = esUrl; } private ConfigUtil() throws Exception { init(); } private void init() throws Exception { InputStream inputStream = this.getClass().getClassLoader() .getResourceAsStream(cfg); SAXReader reader = new SAXReader(); Document doc = reader.read(inputStream); String centerServerUrl = doc.getRootElement().elementTextTrim( "CenterServerUrl"); if (centerServerUrl != null && !centerServerUrl.equals("")) { this.centerServerUrl = centerServerUrl; } this.appId = doc.getRootElement().elementTextTrim("AppId"); this.netWork = doc.getRootElement().elementTextTrim("NetWork"); this.appName = doc.getRootElement().elementTextTrim("AppName"); this.esUrl = doc.getRootElement().elementTextTrim("EsUrl"); try { this.secret = doc.getRootElement().elementTextTrim("OpenPlatformSecret"); } catch (Exception e) { } try { this.openPlatformUrl = doc.getRootElement().elementTextTrim( "openPlatformUrl"); } catch (Exception e) { } inputStream.close(); } public static ConfigUtil getInstance() throws Exception { if (instance == null) { instance = new ConfigUtil(); } return instance; } public static void create() throws Exception { instance = new ConfigUtil(); } }