dataconfigparser.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #include "dataconfigparser.h"
  2. #include "loghelper.h"
  3. DataConfigParser::DataConfigParser()
  4. {
  5. }
  6. bool DataConfigParser::readConfig(QString content)
  7. {
  8. QString errorStr;
  9. int errorLine;
  10. int errorColumn;
  11. QDomDocument doc;
  12. if(!doc.setContent(content,false,&errorStr,&errorLine,&errorColumn))
  13. {
  14. LogHelper::writeLog(errorStr + " " +\
  15. QString::number(errorLine) + " " +QString::number(errorColumn));
  16. return false;
  17. }
  18. QDomElement root = doc.documentElement();
  19. if (root.tagName()!="SpeedNumCube")
  20. {
  21. return false;
  22. }
  23. parseConfigElement(root);
  24. return true;
  25. }
  26. void DataConfigParser::parseConfigElement(const QDomElement &element)
  27. {
  28. QDomNode child = element.firstChild();
  29. while (!child.isNull())
  30. {
  31. if(child.toElement().tagName()=="banner_ad")
  32. {
  33. banner_ad= child.toElement().text();
  34. }
  35. if(child.toElement().tagName()=="banner_topad")
  36. {
  37. banner_topad= child.toElement().text();
  38. }
  39. if(child.toElement().tagName()=="banner_bottomad")
  40. {
  41. banner_bottomad= child.toElement().text();
  42. }
  43. if(child.toElement().tagName()=="helpme_url")
  44. {
  45. helpme_url= child.toElement().text();
  46. }
  47. if(child.toElement().tagName()=="sso_reg_url")
  48. {
  49. sso_reg_url= child.toElement().text();
  50. }
  51. if(child.toElement().tagName()=="sso_pay_url")
  52. {
  53. sso_pay_url= child.toElement().text();
  54. }
  55. if(child.toElement().tagName()=="sso_account_url")
  56. {
  57. sso_account_url= child.toElement().text();
  58. }
  59. if(child.toElement().tagName()=="riddle_url")
  60. {
  61. riddle_url = child.toElement().text();
  62. }
  63. if(child.toElement().tagName()=="website")
  64. {
  65. website_title= child.toElement().text();
  66. website_url = child.toElement().attribute("website_url");
  67. }
  68. if(child.toElement().tagName()=="text_ads")
  69. {
  70. parseAdElement(child.toElement());
  71. }
  72. if(child.toElement().tagName()=="page_ads")
  73. {
  74. parsePageAdElement(child.toElement());
  75. }
  76. if(child.toElement().tagName()=="corp_prefix")
  77. {
  78. parseCorpPrefixElement(child.toElement());
  79. }
  80. if(child.toElement().tagName()=="client_config")
  81. {
  82. client_default_host = child.toElement().attribute("default_host");
  83. client_default_port = child.toElement().attribute("default_port");
  84. parseClientConfigElement(child.toElement());
  85. }
  86. child = child.nextSibling();
  87. }
  88. }
  89. void DataConfigParser::parseAdElement(const QDomElement &element)
  90. {
  91. QDomNode child = element.firstChild();
  92. while (!child.isNull())
  93. {
  94. QString url = child.toElement().attribute("link");
  95. QString content = child.toElement().text();
  96. text_ads.insert(url,content);
  97. child = child.nextSibling();
  98. }
  99. }
  100. void DataConfigParser::parsePageAdElement(const QDomElement &element)
  101. {
  102. QDomNode child = element.firstChild();
  103. while (!child.isNull())
  104. {
  105. QString url = child.toElement().attribute("link");
  106. QString id = child.toElement().text();
  107. page_ads.insert(id,url);
  108. child = child.nextSibling();
  109. }
  110. }
  111. void DataConfigParser::parseCorpPrefixElement(const QDomElement &element)
  112. {
  113. QDomNode child = element.firstChild();
  114. while (!child.isNull())
  115. {
  116. QString corp = child.toElement().attribute("corp");
  117. QString content = child.toElement().text();
  118. corp_prefix.insert(corp,content);
  119. child = child.nextSibling();
  120. }
  121. }
  122. void DataConfigParser::parseClientConfigElement(const QDomElement &element)
  123. {
  124. QDomNode child = element.firstChild();
  125. while (!child.isNull())
  126. {
  127. QStringList list;
  128. QString name = child.toElement().attribute("name");
  129. QString notice_url = child.toElement().attribute("notice_url");
  130. QString host = child.toElement().attribute("host");
  131. QString port = child.toElement().attribute("port");
  132. list<<name<<notice_url<<host<<port;
  133. QString content = child.toElement().text();
  134. client_config.insert(content,list);
  135. child = child.nextSibling();
  136. }
  137. }