-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolxmlparser.cpp
More file actions
117 lines (97 loc) · 2.87 KB
/
polxmlparser.cpp
File metadata and controls
117 lines (97 loc) · 2.87 KB
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
#include "polxmlparser.h"
#include <QFile>
#include <QStringList>
#include <QDebug>
PolXMLParser::PolXMLParser(QString configFile)
{
QFile file(configFile);
if (file.open( QFile::ReadOnly ))
doc.setContent(&file);
//Discard file since it was already loaded by DOMDocument
file.close();
}
QStringList PolXMLParser::getToolsList()
{
QStringList tools;
QDomElement root = doc.documentElement();
if (root.tagName() != "PolToolBox")
return tools;
//Get tools
QDomNode n = root.firstChild();
while ( !n.isNull() ){
QDomElement e = n.toElement();
if (!e.isNull()) {
if (e.tagName() == "tool") {
QDomNodeList lst = e.elementsByTagName("name");
if (lst.size() != 1) {
qDebug() << "PolXMLParser::getToolsList : Enoutered multiple names for same tool!";
}
QString name = lst.at(0).toElement().text();
tools << name;
}
}
n = n.nextSibling();
}
return tools;
}
QString PolXMLParser::getAuthor(QString appName)
{
QString author = "";
QDomElement a = getNodeOfAppName(appName);
if (a.isNull())
return author;
QDomNodeList l = a.elementsByTagName("author");
if (l.size() != 1)
return author;
return l.at(0).toElement().text();
}
QDomNodeList PolXMLParser::getParameters(QString appName)
{
QDomElement d = getNodeOfAppName(appName);
if (d.isNull())
return QDomNodeList();
QDomNodeList l = d.elementsByTagName("param");
return l;
}
QDomNodeList PolXMLParser::getOptions(QString appName)
{
QDomElement d = getNodeOfAppName(appName);
if (d.isNull())
return QDomNodeList();
QDomNodeList l = d.elementsByTagName("option");
return l;
}
QString PolXMLParser::getDescription(QString appName)
{
QString descr = "";
QDomElement d = getNodeOfAppName(appName);
if (d.isNull())
return descr;
QDomNodeList l = d.elementsByTagName("description");
if (l.size() < 1)
return descr;
return l.at(0).toElement().text();
}
QDomElement PolXMLParser::getNodeOfAppName(QString appName)
{
QDomElement root = doc.documentElement();
if (root.tagName() != "PolToolBox")
return QDomElement();
QDomNode n = root.firstChild();
while ( !n.isNull() ){
QDomElement e = n.toElement();
if (!e.isNull()) {
if (e.tagName() == "tool") {
QDomNodeList lst = e.elementsByTagName("name");
if (lst.size() != 1) {
qDebug() << "PolXMLParser::getToolsList : Enoutered multiple names for same tool!";
}
QString name = lst.at(0).toElement().text();
if (name == appName)
return e;
}
}
n = n.nextSibling();
}
return QDomElement();
}