-
Notifications
You must be signed in to change notification settings - Fork 7
/
configxmlfile.cpp
120 lines (108 loc) · 3.13 KB
/
configxmlfile.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "configxmlfile.h"
#include "confighelper.h"
ConfigXmlFile::ConfigXmlFile(QString fileName) : ConfigFile(fileName), m_DomDocument(fileName)
{
ConfigType = "ConfigXmlFile";
//QString *error;
//doc.setContent(this->ConfigContents, error);
if(!m_DomDocument.setContent(this->ConfigContents))
{
this->loadSuccess = false;
return;
}
this->loadSuccess = true;
m_DocElem = m_DomDocument.documentElement();
}
ConfigXmlFile::~ConfigXmlFile()
{
}
QString ConfigXmlFile::SetConfigElement(QString name, QMap<QString,QString> attributes, QString value)
{
QDomElement e;
QString ret = GetDomElement(name, e);
if(ret!="Success"){return ret;}
if(name==e.nodeName())
{
QDomNamedNodeMap attrMap = e.attributes();
foreach(QString key, attributes.keys())
{
QString attrKey = key;
if(attrKey.startsWith("Config:")){
attrKey = attrKey.mid(7);
}
if(attrMap.contains(attrKey))
{
QDomNode node = attrMap.namedItem(attrKey);
QDomAttr attr = node.toAttr();
//attr.setNodeValue(attributes[key]);
QString val = attributes.value(key);
val = ConfigHelper::RemoveQuotes(val);
attr.setValue(val);
//attr.setValue(attributes[key]);
}
else
{
return key + " attribute not found";
if(value!=""){
//TODO: set value
}
/*
QDomAttr* attr = new QDomAttr();
attr->setValue(attributes[key]);
//*/
}
}
return "Success";
}
return "Internal error";
}
QString ConfigXmlFile::GetConfigElement(QString name, QMap<QString,QString> & attributes, QString & value)
{
/*
QDomNodeList nodelist = m_DocElem.elementsByTagName(name);
if(nodelist.count()>1)
{
return "Ambiguous";
}
if(nodelist.count()==0)
{
return "Not found";
}
QDomElement e = ((QDomNode)nodelist.at(0)).toElement();
//*/
QDomElement e;
QString ret = GetDomElement(name, e);
if(ret!="Success"){return ret;}
if(name==e.nodeName()){
QDomNamedNodeMap attrMap = e.attributes();
for(int j=0;j<attrMap.count();j++)
{
QDomNode n = attrMap.item(j);
QDomAttr attr = n.toAttr();
//QDomAttr attr = ((QDomAttr)attrMap.item(j)).toAttr();
attributes.insert(attr.name(), attr.value());
}
value = e.nodeValue();
return "Success";
}
return "Internal error";
}
QString ConfigXmlFile::GetDomElement(QString name, QDomElement& element)
{
QDomNodeList nodelist = m_DocElem.elementsByTagName(name);
if(nodelist.count()>1)
{
return "Ambiguous";
}
if(nodelist.count()==0)
{
return "Not found";
}
element = ((QDomNode)nodelist.at(0)).toElement();
return "Success";
}
void ConfigXmlFile::UpdateFile()
{
this->ConfigContents.clear();
this->ConfigContents = m_DomDocument.toString();
}