| 51 |
|
pugi::xml_document newNode; |
| 52 |
|
pugi::xml_parse_result result; |
| 53 |
|
|
| 54 |
< |
filesToProcess=UtilXmlTools::getAllXmlFilesByWildcard(filesWildcard); |
| 54 |
> |
try{ |
| 55 |
|
|
| 56 |
< |
if(filesToProcess.isEmpty()){ |
| 57 |
< |
UtilXmlTools::displayErrorMessage("@ADD_INSIDE_NODES","No XML files were found for the wildcard: "+filesWildcard); |
| 58 |
< |
} |
| 59 |
< |
|
| 60 |
< |
result=newNode.load(xmlString.toUtf8().constData()); // load xml to insert |
| 61 |
< |
|
| 62 |
< |
if(result.status!=pugi::status_ok){ |
| 63 |
< |
UtilXmlTools::displayErrorMessage("@ADD_INSIDE_NODES", "The xml node to insert is invalid.\n" + Util::toQString(result.description())); |
| 64 |
< |
} |
| 56 |
> |
filesToProcess=UtilXmlTools::getAllXmlFilesByWildcard(filesWildcard); |
| 57 |
|
|
| 58 |
< |
// Process all XmlFiles |
| 59 |
< |
for(int i=0; i<filesToProcess.size(); i++){ |
| 58 |
> |
if(filesToProcess.isEmpty()){ |
| 59 |
> |
UtilXmlTools::displayErrorMessage("@ADD_INSIDE_NODES","No XML files were found for the wildcard: "+filesWildcard); |
| 60 |
> |
} |
| 61 |
|
|
| 62 |
< |
UtilXmlTools::loadXmlFile(filesToProcess[i],this->document,this->rootNode,this->backupsEnabled,this->verboseEnabled,"@ADD_INSIDE_NODES"); |
| 62 |
> |
result=newNode.load(xmlString.toUtf8().constData()); // load xml to insert |
| 63 |
|
|
| 64 |
< |
// Check how the element will be fetched via element name or xpath expression |
| 65 |
< |
if(xPathExpression.isEmpty()){ |
| 73 |
< |
UtilXmlTools::getAllNamedElements(this->rootNode,nodesToInsertion,filters); |
| 74 |
< |
} |
| 75 |
< |
else{ |
| 76 |
< |
UtilXmlTools::getAllXpathElements(xPathExpression,this->document,nodesToInsertion); |
| 64 |
> |
if(result.status!=pugi::status_ok){ |
| 65 |
> |
UtilXmlTools::displayErrorMessage("@ADD_INSIDE_NODES", "The xml node to insert is invalid.\n" + Util::toQString(result.description())); |
| 66 |
|
} |
| 67 |
|
|
| 68 |
< |
if(nodesToInsertion.isEmpty() || nodesToInsertion[0].type()==pugi::node_null){ |
| 68 |
> |
// Process all XmlFiles |
| 69 |
> |
for(int i=0; i<filesToProcess.size(); i++){ |
| 70 |
|
|
| 71 |
< |
QString errMessage; |
| 71 |
> |
UtilXmlTools::loadXmlFile(filesToProcess[i],this->document,this->rootNode,this->backupsEnabled,this->verboseEnabled,"@ADD_INSIDE_NODES"); |
| 72 |
|
|
| 73 |
+ |
// Check how the element will be fetched via element name or xpath expression |
| 74 |
|
if(xPathExpression.isEmpty()){ |
| 75 |
< |
errMessage = "No node was found with an ElementName: '" + filters.getElementName() + "'"; |
| 85 |
< |
if(filters.getParentElementName()!=""){ |
| 86 |
< |
errMessage += " and a ParentElementName: '" + filters.getParentElementName() + "'"; |
| 87 |
< |
} |
| 88 |
< |
if(filters.getAttributeName()!=""){ |
| 89 |
< |
errMessage += " and an AttributeName: '" + filters.getAttributeName() + "' and an AttributeValue: '" + filters.getAttributeValue() + "'"; |
| 90 |
< |
} |
| 75 |
> |
UtilXmlTools::getAllNamedElements(this->rootNode,nodesToInsertion,filters); |
| 76 |
|
} |
| 77 |
|
else{ |
| 78 |
< |
errMessage = "No node was found with an XPathExpression: '" + xPathExpression + "'"; |
| 78 |
> |
UtilXmlTools::getAllXpathElements(xPathExpression,this->document,nodesToInsertion); |
| 79 |
|
} |
| 80 |
|
|
| 81 |
< |
UtilXmlTools::displayErrorMessage("@ADD_INSIDE_NODES",errMessage); |
| 82 |
< |
} |
| 81 |
> |
if(nodesToInsertion.isEmpty() || nodesToInsertion[0].type()==pugi::node_null){ |
| 82 |
> |
|
| 83 |
> |
QString errMessage; |
| 84 |
|
|
| 85 |
< |
for(int j=0; j<nodesToInsertion.size(); j++){ |
| 86 |
< |
for (pugi::xml_node currNodeToInsert = newNode.first_child(); currNodeToInsert; currNodeToInsert = currNodeToInsert.next_sibling()) |
| 87 |
< |
{ |
| 88 |
< |
nodesToInsertion[j].append_copy(currNodeToInsert); // append the new node |
| 85 |
> |
if(xPathExpression.isEmpty()){ |
| 86 |
> |
errMessage = "No node was found with an ElementName: '" + filters.getElementName() + "'"; |
| 87 |
> |
if(filters.getParentElementName()!=""){ |
| 88 |
> |
errMessage += " and a ParentElementName: '" + filters.getParentElementName() + "'"; |
| 89 |
> |
} |
| 90 |
> |
if(filters.getAttributeName()!=""){ |
| 91 |
> |
errMessage += " and an AttributeName: '" + filters.getAttributeName() + "' and an AttributeValue: '" + filters.getAttributeValue() + "'"; |
| 92 |
> |
} |
| 93 |
> |
} |
| 94 |
> |
else{ |
| 95 |
> |
errMessage = "No node was found with an XPathExpression: '" + xPathExpression + "'"; |
| 96 |
> |
} |
| 97 |
> |
|
| 98 |
> |
UtilXmlTools::displayErrorMessage("@ADD_INSIDE_NODES",errMessage); |
| 99 |
|
} |
| 100 |
|
|
| 101 |
< |
} |
| 101 |
> |
for(int j=0; j<nodesToInsertion.size(); j++){ |
| 102 |
> |
for (pugi::xml_node currNodeToInsert = newNode.first_child(); currNodeToInsert; currNodeToInsert = currNodeToInsert.next_sibling()) |
| 103 |
> |
{ |
| 104 |
> |
nodesToInsertion[j].append_copy(currNodeToInsert); // append the new node |
| 105 |
> |
} |
| 106 |
> |
|
| 107 |
> |
} |
| 108 |
|
|
| 109 |
< |
UtilXmlTools::saveXmlFile(filesToProcess[i],this->document, "@ADD_INSIDE_NODES"); |
| 109 |
> |
UtilXmlTools::saveXmlFile(filesToProcess[i],this->document, "@ADD_INSIDE_NODES"); |
| 110 |
|
|
| 111 |
< |
nodesToInsertion.clear(); |
| 111 |
> |
nodesToInsertion.clear(); |
| 112 |
> |
} |
| 113 |
> |
} |
| 114 |
> |
catch(const std::exception &e){ |
| 115 |
> |
UtilXmlTools::displayErrorMessage("@ADD_INSIDE_NODES", QString("An exception was caught: ") + e.what()); |
| 116 |
|
} |
| 117 |
|
|
| 118 |
|
UtilXmlTools::displaySuccessMessage(filesToProcess.size(),"@ADD_INSIDE_NODES"); |
| 124 |
|
|
| 125 |
|
QList<pugi::xml_node> nodesToDeletion; |
| 126 |
|
|
| 127 |
< |
filesToProcess=UtilXmlTools::getAllXmlFilesByWildcard(filesWildcard); |
| 127 |
> |
try{ |
| 128 |
|
|
| 129 |
< |
if(filesToProcess.isEmpty()){ |
| 124 |
< |
UtilXmlTools::displayErrorMessage("@REMOVE_NODES","No XML files were found for the wildcard: "+filesWildcard); |
| 125 |
< |
} |
| 126 |
< |
|
| 127 |
< |
// Process all XmlFiles |
| 128 |
< |
for(int i=0; i<filesToProcess.size(); i++){ |
| 129 |
> |
filesToProcess=UtilXmlTools::getAllXmlFilesByWildcard(filesWildcard); |
| 130 |
|
|
| 131 |
< |
UtilXmlTools::loadXmlFile(filesToProcess[i],this->document,this->rootNode,this->backupsEnabled,this->verboseEnabled,"@REMOVE_NODES"); |
| 132 |
< |
|
| 132 |
< |
// Check how the element will be fetched via element name or xpath expression |
| 133 |
< |
if(xPathExpression.isEmpty()){ |
| 134 |
< |
UtilXmlTools::getAllNamedElements(this->rootNode,nodesToDeletion,filters); |
| 135 |
< |
} |
| 136 |
< |
else{ |
| 137 |
< |
UtilXmlTools::getAllXpathElements(xPathExpression,this->document,nodesToDeletion); |
| 131 |
> |
if(filesToProcess.isEmpty()){ |
| 132 |
> |
UtilXmlTools::displayErrorMessage("@REMOVE_NODES","No XML files were found for the wildcard: "+filesWildcard); |
| 133 |
|
} |
| 134 |
|
|
| 135 |
< |
if(nodesToDeletion.isEmpty() || nodesToDeletion[0].type()==pugi::node_null){ |
| 135 |
> |
// Process all XmlFiles |
| 136 |
> |
for(int i=0; i<filesToProcess.size(); i++){ |
| 137 |
|
|
| 138 |
< |
QString errMessage; |
| 138 |
> |
UtilXmlTools::loadXmlFile(filesToProcess[i],this->document,this->rootNode,this->backupsEnabled,this->verboseEnabled,"@REMOVE_NODES"); |
| 139 |
|
|
| 140 |
+ |
// Check how the element will be fetched via element name or xpath expression |
| 141 |
|
if(xPathExpression.isEmpty()){ |
| 142 |
< |
errMessage = "No node was found with an ElementName: '" + filters.getElementName() + "'"; |
| 146 |
< |
if(filters.getParentElementName()!=""){ |
| 147 |
< |
errMessage += " and a ParentElementName: '" + filters.getParentElementName() + "'"; |
| 148 |
< |
} |
| 149 |
< |
if(filters.getAttributeName()!=""){ |
| 150 |
< |
errMessage += " and an AttributeName: '" + filters.getAttributeName() + "' and an AttributeValue: '" + filters.getAttributeValue() + "'"; |
| 151 |
< |
} |
| 142 |
> |
UtilXmlTools::getAllNamedElements(this->rootNode,nodesToDeletion,filters); |
| 143 |
|
} |
| 144 |
|
else{ |
| 145 |
< |
errMessage = "No node was found with an XPathExpression: '" + xPathExpression + "'"; |
| 145 |
> |
UtilXmlTools::getAllXpathElements(xPathExpression,this->document,nodesToDeletion); |
| 146 |
|
} |
| 147 |
|
|
| 148 |
< |
UtilXmlTools::displayErrorMessage("@REMOVE_NODES",errMessage); |
| 158 |
< |
} |
| 159 |
< |
|
| 160 |
< |
// Delete all the specified nodes |
| 161 |
< |
for(int j=0; j<nodesToDeletion.size(); j++){ |
| 162 |
< |
if(!nodesToDeletion[j].parent().remove_child(nodesToDeletion[j])){ // remove the node |
| 148 |
> |
if(nodesToDeletion.isEmpty() || nodesToDeletion[0].type()==pugi::node_null){ |
| 149 |
|
|
| 150 |
|
QString errMessage; |
| 165 |
– |
if(xPathExpression.isEmpty()){ |
| 166 |
– |
errMessage = "Couldn't remove the node with Element '" + filters.getElementName() + "'"; |
| 151 |
|
|
| 152 |
+ |
if(xPathExpression.isEmpty()){ |
| 153 |
+ |
errMessage = "No node was found with an ElementName: '" + filters.getElementName() + "'"; |
| 154 |
|
if(filters.getParentElementName()!=""){ |
| 155 |
< |
errMessage += " and a ParentElement: '" + filters.getParentElementName() + "'"; |
| 155 |
> |
errMessage += " and a ParentElementName: '" + filters.getParentElementName() + "'"; |
| 156 |
> |
} |
| 157 |
> |
if(filters.getAttributeName()!=""){ |
| 158 |
> |
errMessage += " and an AttributeName: '" + filters.getAttributeName() + "' and an AttributeValue: '" + filters.getAttributeValue() + "'"; |
| 159 |
|
} |
| 160 |
|
} |
| 161 |
|
else{ |
| 162 |
< |
errMessage = "Couldn't remove the node with the XPathExpression '" + xPathExpression + "'"; |
| 162 |
> |
errMessage = "No node was found with an XPathExpression: '" + xPathExpression + "'"; |
| 163 |
|
} |
| 164 |
|
|
| 165 |
|
UtilXmlTools::displayErrorMessage("@REMOVE_NODES",errMessage); |
| 166 |
|
} |
| 178 |
– |
} |
| 167 |
|
|
| 168 |
< |
UtilXmlTools::saveXmlFile(filesToProcess[i],this->document, "@REMOVE_NODES"); |
| 168 |
> |
// Delete all the specified nodes |
| 169 |
> |
for(int j=0; j<nodesToDeletion.size(); j++){ |
| 170 |
> |
if(!nodesToDeletion[j].parent().remove_child(nodesToDeletion[j])){ // remove the node |
| 171 |
> |
|
| 172 |
> |
QString errMessage; |
| 173 |
> |
if(xPathExpression.isEmpty()){ |
| 174 |
> |
errMessage = "Couldn't remove the node with Element '" + filters.getElementName() + "'"; |
| 175 |
> |
|
| 176 |
> |
if(filters.getParentElementName()!=""){ |
| 177 |
> |
errMessage += " and a ParentElement: '" + filters.getParentElementName() + "'"; |
| 178 |
> |
} |
| 179 |
> |
} |
| 180 |
> |
else{ |
| 181 |
> |
errMessage = "Couldn't remove the node with the XPathExpression '" + xPathExpression + "'"; |
| 182 |
> |
} |
| 183 |
> |
|
| 184 |
> |
UtilXmlTools::displayErrorMessage("@REMOVE_NODES",errMessage); |
| 185 |
> |
} |
| 186 |
> |
} |
| 187 |
> |
|
| 188 |
> |
UtilXmlTools::saveXmlFile(filesToProcess[i],this->document, "@REMOVE_NODES"); |
| 189 |
|
|
| 190 |
< |
nodesToDeletion.clear(); |
| 190 |
> |
nodesToDeletion.clear(); |
| 191 |
> |
} |
| 192 |
> |
} |
| 193 |
> |
catch(const std::exception &e){ |
| 194 |
> |
UtilXmlTools::displayErrorMessage("@REMOVE_NODES", QString("An exception was caught: ") + e.what()); |
| 195 |
|
} |
| 196 |
|
|
| 197 |
|
UtilXmlTools::displaySuccessMessage(filesToProcess.size(), "@REMOVE_NODES"); |
| 227 |
|
|
| 228 |
|
QVector<QString> filesToProcess=UtilXmlTools::getAllXmlFilesByWildcard(filesWildcard); |
| 229 |
|
|
| 230 |
< |
if(filesToProcess.isEmpty()){ |
| 231 |
< |
UtilXmlTools::displayErrorMessage("@CUSTOM_CODE","No XML files were found for the wildcard: "+filesWildcard); |
| 232 |
< |
} |
| 233 |
< |
|
| 222 |
< |
XmlCustomCode::getInstance()->executeCustomCode(jsString,filesToProcess,this->backupsEnabled,this->verboseEnabled); |
| 230 |
> |
try{ |
| 231 |
> |
if(filesToProcess.isEmpty()){ |
| 232 |
> |
UtilXmlTools::displayErrorMessage("@CUSTOM_CODE","No XML files were found for the wildcard: "+filesWildcard); |
| 233 |
> |
} |
| 234 |
|
|
| 235 |
+ |
XmlCustomCode::getInstance()->executeCustomCode(jsString,filesToProcess,this->backupsEnabled,this->verboseEnabled); |
| 236 |
+ |
} |
| 237 |
+ |
catch(const std::exception &e){ |
| 238 |
+ |
UtilXmlTools::displayErrorMessage("@CUSTOM_CODE", QString("An exception was caught: ") + e.what()); |
| 239 |
+ |
} |
| 240 |
|
|
| 241 |
|
UtilXmlTools::displaySuccessMessage(filesToProcess.size(), "@CUSTOM_CODE"); |
| 242 |
|
} |