23 #include "updaterscriptparser.h" 25 #include "autoupdater.h" 29 DClass<UpdaterScriptParser>
42 UpdaterScriptParser::~UpdaterScriptParser()
46 QDomNode UpdaterScriptParser::installNode(
const QDomDocument &doc)
48 return doc.elementsByTagName(
"update").at(0).toElement()
49 .elementsByTagName(
"install").at(0);
52 QDomElement UpdaterScriptParser::mainElement()
54 QDomNodeList nodes = d->pDoc->elementsByTagName(
"update");
55 return nodes.at(0).toElement();
60 assert(d->pDoc !=
nullptr &&
"UpdaterScriptParser::merge()");
61 if (!d->pDoc->isNull())
63 QDomNodeList listNodes;
67 QDomNode nodePackagesDst = packagesNode(*d->pDoc);
68 QDomNode nodePackagesSrc = packagesNode(otherDoc);
69 listNodes = nodePackagesSrc.toElement().elementsByTagName(
"package");
70 for (
int i = 0; i < listNodes.count(); ++i)
72 nodePackagesDst.appendChild(listNodes.at(i).cloneNode(
true));
75 QDomNode nodeInstallDst = installNode(*d->pDoc);
76 QDomNode nodeInstallSrc = installNode(otherDoc);
77 listNodes = nodeInstallSrc.toElement().elementsByTagName(
"file");
78 for (
int i = 0; i < listNodes.count(); ++i)
80 nodeInstallDst.appendChild(listNodes.at(i).cloneNode(
true));
85 *d->pDoc = otherDoc.cloneNode().toDocument();
89 QString UpdaterScriptParser::msgMainElementMissingError()
91 return AutoUpdater::tr(
"Missing main \"update\" node.");
94 QDomNode UpdaterScriptParser::packagesNode(
const QDomDocument &doc)
96 return doc.elementsByTagName(
"update").at(0).toElement()
97 .elementsByTagName(
"packages").at(0);
102 assert(d->pDoc !=
nullptr &&
"UpdaterScriptParser::setPackageName()");
104 errorMsg = setPackageNameInPackages(name);
105 if (errorMsg.isNull())
107 errorMsg = setPackageNameInFiles(name);
112 QString UpdaterScriptParser::setPackageNameInFiles(
const QString &name)
118 element = mainElement();
119 if (element.isNull())
121 return msgMainElementMissingError();
123 element = element.elementsByTagName(
"install").at(0).toElement();
124 if (element.isNull())
126 return AutoUpdater::tr(
"Missing \"install\" element.");
128 nodes = element.elementsByTagName(
"file");
129 for (
int i = 0; i < nodes.count(); ++i)
131 QDomNode textNode = nodes.at(i).toElement()
132 .elementsByTagName(
"package").at(0).toElement().firstChild();
133 textNode.setNodeValue(name);
134 if (textNode.isNull())
136 return AutoUpdater::tr(
"Missing text node for \"package\" " 137 "element for \"file\" element %1").arg(i);
143 QString UpdaterScriptParser::setPackageNameInPackages(
const QString &name)
149 element = mainElement();
150 if (element.isNull())
152 return msgMainElementMissingError();
155 nodes = element.elementsByTagName(
"packages");
158 return AutoUpdater::tr(
"Missing \"packages\" element.");
160 element = nodes.at(0).toElement();
167 nodes = element.elementsByTagName(
"package");
168 if (nodes.size() != 1)
170 if (nodes.size() > 1)
172 return AutoUpdater::tr(
"More than one \"package\" element found.");
174 return AutoUpdater::tr(
"Missing \"package\" element.");
178 QDomNode nameTextNode = nodes.at(0).toElement()
179 .elementsByTagName(
"name").at(0).toElement().firstChild();
180 nameTextNode.setNodeValue(name);
181 if (nameTextNode.isNull())
183 return AutoUpdater::tr(
"Failed to find \"name\" text node.");
Interface to Mendeley updater .xml script files.
QString setPackageName(const QString &name)
Sets value of package name tags in the script file.
void merge(const QDomDocument &otherDoc)
Merges other script with current script.