414c55d4fb3becb36ed35a9344b273ed29d7f41c.svn-base 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. *
  3. */
  4. package com.yihu.base;
  5. import java.io.InputStream;
  6. import org.dom4j.Document;
  7. import org.dom4j.io.SAXReader;
  8. import com.yihu.utils.SecretUtil;
  9. /**
  10. * 获取sys.xml配置
  11. */
  12. public class ConfigUtil {
  13. private static ConfigUtil instance = null;
  14. private static final String cfg = "sys.xml";
  15. private String secret;// 秘钥
  16. private String openPlatformUrl;// 开放平台接口网址
  17. private String centerServerUrl;
  18. private String appId;
  19. private String netWork;
  20. private String appName;
  21. private String esUrl;
  22. public String getSecret() {
  23. return secret;
  24. }
  25. public String getOpenPlatformUrl() {
  26. return openPlatformUrl;
  27. }
  28. public String getCenterServerUrl() {
  29. return centerServerUrl;
  30. }
  31. public String getAppId() {
  32. return appId;
  33. }
  34. public void setAppId(String appId) {
  35. this.appId = appId;
  36. }
  37. public String getNetWork() {
  38. return netWork;
  39. }
  40. public void setNetWork(String netWork) {
  41. this.netWork = netWork;
  42. }
  43. public String getAppName() {
  44. return appName;
  45. }
  46. public String getEsUrl() {
  47. return esUrl;
  48. }
  49. public void setEsUrl(String esUrl) {
  50. this.esUrl = esUrl;
  51. }
  52. private ConfigUtil() throws Exception {
  53. init();
  54. }
  55. private void init() throws Exception {
  56. InputStream inputStream = this.getClass().getClassLoader()
  57. .getResourceAsStream(cfg);
  58. SAXReader reader = new SAXReader();
  59. Document doc = reader.read(inputStream);
  60. String centerServerUrl = doc.getRootElement().elementTextTrim(
  61. "CenterServerUrl");
  62. if (centerServerUrl != null && !centerServerUrl.equals("")) {
  63. this.centerServerUrl = centerServerUrl;
  64. }
  65. this.appId = doc.getRootElement().elementTextTrim("AppId");
  66. this.netWork = doc.getRootElement().elementTextTrim("NetWork");
  67. this.appName = doc.getRootElement().elementTextTrim("AppName");
  68. this.esUrl = doc.getRootElement().elementTextTrim("EsUrl");
  69. try {
  70. this.secret = doc.getRootElement().elementTextTrim("OpenPlatformSecret");
  71. } catch (Exception e) {
  72. }
  73. try {
  74. this.openPlatformUrl = doc.getRootElement().elementTextTrim(
  75. "openPlatformUrl");
  76. } catch (Exception e) {
  77. }
  78. inputStream.close();
  79. }
  80. public static ConfigUtil getInstance() throws Exception {
  81. if (instance == null) {
  82. instance = new ConfigUtil();
  83. }
  84. return instance;
  85. }
  86. public static void create() throws Exception {
  87. instance = new ConfigUtil();
  88. }
  89. }