ConfigManager.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. function ConfigManger(configPath) {
  2. var m_configPath = "";
  3. var m_xmlDoc = null;
  4. if (configPath != null && configPath != "")
  5. m_configPath = configPath;
  6. else
  7. m_configPath = "config_local.xml";
  8. if (m_configPath == null || m_configPath == "")
  9. return null;
  10. var xmlHelper = new XmlHelper();
  11. var m_xmlDoc = xmlHelper.loadFileXml(m_configPath); //获取工具栏信息
  12. if (m_xmlDoc == null)
  13. return null;
  14. //获取配置信息
  15. this.GetConfigValue = function (keyName) {
  16. if (m_xmlDoc == null)
  17. return null;
  18. var data = m_xmlDoc.getElementsByTagName(keyName); //获得所有子节点
  19. //var value = data[0].text;
  20. var xmlHelper = new XmlHelper();
  21. var value = xmlHelper.getNodeValue(data[0]);
  22. return value;
  23. }
  24. }
  25. var xmlUtil;
  26. var xmlDoc;
  27. function GetConfigData(){
  28. xmlUtil = new XMLUtil();
  29. xmlDoc = xmlUtil.loadXmlFromFile(getRootPath_dc()+"/config/config_local.xml");
  30. }
  31. function GetConfigValueByTagName(tagName)
  32. {
  33. if(isEmptyValue(xmlUtil))
  34. GetConfigData();
  35. var configNode = xmlDoc.getElementsByTagName(tagName);
  36. var stringUrl = xmlUtil.getNodeValue(configNode[0]);
  37. return stringUrl;
  38. }
  39. function getRootPath_web() {
  40. //获取当前网址,如: http://localhost:8083/uimcardprj/share/meun.jsp
  41. var curWwwPath = window.document.location.href;
  42. //获取主机地址之后的目录,如: uimcardprj/share/meun.jsp
  43. var pathName = window.document.location.pathname;
  44. var pos = curWwwPath.indexOf(pathName);
  45. //获取主机地址,如: http://localhost:8083
  46. var localhostPaht = curWwwPath.substring(0, pos);
  47. //获取带"/"的项目名,如:/uimcardprj
  48. var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
  49. return (localhostPaht + projectName);
  50. }
  51. function getRootPath_dc() {
  52. var pathName = window.location.pathname.substring(1);
  53. var webName = pathName == '' ? '' : pathName.substring(0, pathName.indexOf('/'));
  54. if (webName == "") {
  55. return window.location.protocol + '//' + window.location.host;
  56. }
  57. else {
  58. return window.location.protocol + '//' + window.location.host + '/' + webName;
  59. }
  60. }
  61. function GetConfigDataByName(nodeName) {
  62. var nodeXml = xmlDoc.getElementsByTagName(nodeName);
  63. var nodeValue = xmlUtil.getNodeValue(nodeXml[0]);
  64. return nodeValue;
  65. }