| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- #include "dataconfigparser.h"
- #include "loghelper.h"
- DataConfigParser::DataConfigParser()
- {
- }
- bool DataConfigParser::readConfig(QString content)
- {
- QString errorStr;
- int errorLine;
- int errorColumn;
- QDomDocument doc;
- if(!doc.setContent(content,false,&errorStr,&errorLine,&errorColumn))
- {
- LogHelper::writeLog(errorStr + " " +\
- QString::number(errorLine) + " " +QString::number(errorColumn));
- return false;
- }
- QDomElement root = doc.documentElement();
- if (root.tagName()!="SpeedNumCube")
- {
- return false;
- }
- parseConfigElement(root);
- return true;
- }
- void DataConfigParser::parseConfigElement(const QDomElement &element)
- {
- QDomNode child = element.firstChild();
- while (!child.isNull())
- {
- if(child.toElement().tagName()=="banner_ad")
- {
- banner_ad= child.toElement().text();
- }
- if(child.toElement().tagName()=="banner_topad")
- {
- banner_topad= child.toElement().text();
- }
- if(child.toElement().tagName()=="banner_bottomad")
- {
- banner_bottomad= child.toElement().text();
- }
- if(child.toElement().tagName()=="helpme_url")
- {
- helpme_url= child.toElement().text();
- }
- if(child.toElement().tagName()=="sso_reg_url")
- {
- sso_reg_url= child.toElement().text();
- }
- if(child.toElement().tagName()=="sso_pay_url")
- {
- sso_pay_url= child.toElement().text();
- }
- if(child.toElement().tagName()=="sso_account_url")
- {
- sso_account_url= child.toElement().text();
- }
- if(child.toElement().tagName()=="riddle_url")
- {
- riddle_url = child.toElement().text();
- }
- if(child.toElement().tagName()=="website")
- {
- website_title= child.toElement().text();
- website_url = child.toElement().attribute("website_url");
- }
- if(child.toElement().tagName()=="text_ads")
- {
- parseAdElement(child.toElement());
- }
- if(child.toElement().tagName()=="page_ads")
- {
- parsePageAdElement(child.toElement());
- }
- if(child.toElement().tagName()=="corp_prefix")
- {
- parseCorpPrefixElement(child.toElement());
- }
- if(child.toElement().tagName()=="client_config")
- {
- client_default_host = child.toElement().attribute("default_host");
- client_default_port = child.toElement().attribute("default_port");
- parseClientConfigElement(child.toElement());
- }
- child = child.nextSibling();
- }
- }
- void DataConfigParser::parseAdElement(const QDomElement &element)
- {
- QDomNode child = element.firstChild();
- while (!child.isNull())
- {
- QString url = child.toElement().attribute("link");
- QString content = child.toElement().text();
- text_ads.insert(url,content);
- child = child.nextSibling();
- }
- }
- void DataConfigParser::parsePageAdElement(const QDomElement &element)
- {
- QDomNode child = element.firstChild();
- while (!child.isNull())
- {
- QString url = child.toElement().attribute("link");
- QString id = child.toElement().text();
- page_ads.insert(id,url);
- child = child.nextSibling();
- }
- }
- void DataConfigParser::parseCorpPrefixElement(const QDomElement &element)
- {
- QDomNode child = element.firstChild();
- while (!child.isNull())
- {
- QString corp = child.toElement().attribute("corp");
- QString content = child.toElement().text();
- corp_prefix.insert(corp,content);
- child = child.nextSibling();
- }
- }
- void DataConfigParser::parseClientConfigElement(const QDomElement &element)
- {
- QDomNode child = element.firstChild();
- while (!child.isNull())
- {
- QStringList list;
- QString name = child.toElement().attribute("name");
- QString notice_url = child.toElement().attribute("notice_url");
- QString host = child.toElement().attribute("host");
- QString port = child.toElement().attribute("port");
- list<<name<<notice_url<<host<<port;
- QString content = child.toElement().text();
- client_config.insert(content,list);
- child = child.nextSibling();
- }
- }
|