From: Hosang Kim Date: Fri, 7 Apr 2023 10:17:03 +0000 (+0900) Subject: AurumXML: fix find elements for XPath. X-Git-Tag: accepted/tizen/unified/20230413.123737^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F74%2F291074%2F1;p=platform%2Fcore%2Fuifw%2Faurum.git AurumXML: fix find elements for XPath. The previous approach involved creating a new tree and then finding the item, but it has been modified to first find the item and if unsuccessful, then create a new tree. Change-Id: I409a4af4d7bb6a4bcfb13bfdab002fd78a2b1e20 --- diff --git a/libaurum/inc/AurumXML.h b/libaurum/inc/AurumXML.h index 9bc84a4..f4cf4c8 100644 --- a/libaurum/inc/AurumXML.h +++ b/libaurum/inc/AurumXML.h @@ -142,6 +142,21 @@ private: */ std::shared_ptr checkParentNode(const std::shared_ptr& node); + /** + * @internal + * + * @brief Finds XNode that satisfied with the xpath in the object tree. + * + * @param ret vector contains objects + * + * @param xpath + * + * @param earlyReturn + * + * @since_tizen 7.5 + */ + void findXNodes(std::vector> &ret, std::string xpath, bool earlyReturn); + private: xml_document *mDoc; const std::shared_ptr mRoot; diff --git a/libaurum/src/AurumXML.cc b/libaurum/src/AurumXML.cc index 8f3ba78..36dfa1b 100644 --- a/libaurum/src/AurumXML.cc +++ b/libaurum/src/AurumXML.cc @@ -46,7 +46,6 @@ void AurumXML::traverse(xml_node& element, const std::shared_ptr node->updateRoleName(); node->updateAttributes(); node->updateToolkitName(); - node->updateApplication(); std::string name; if (node->getType().empty()) @@ -54,7 +53,10 @@ void AurumXML::traverse(xml_node& element, const std::shared_ptr else name = node->getType(); - if (!name.compare("application")) name = node->getPkg(); + if (!name.compare("application")) { + node->updateApplication(); + name = node->getPkg(); + } // Remove white spaces. name.erase(remove(name.begin(), name.end(), ' '), name.end()); @@ -68,7 +70,7 @@ void AurumXML::traverse(xml_node& element, const std::shared_ptr mXNodeMap[node->getId()] = node; auto children = node->getChildren(); - for (auto &child : children) + for (const auto &child : children) { if (child->getRawHandler() == nullptr) continue; @@ -84,7 +86,7 @@ bool AurumXML::createXMLtree() mDoc->remove_children(); xml_node element = mDoc->append_child(""); - + traverse(element, mRoot); return true; @@ -167,7 +169,7 @@ std::shared_ptr AurumXML::checkParentNode(const std::shared_ptr< if (xmlNode) { auto children = node->getChildren(); - for (auto &child : children) { + for (const auto &child : children) { if (child->getRawHandler() == nullptr) continue; xml_node childElement = xmlNode.append_child(""); @@ -214,26 +216,33 @@ std::string AurumXML::getXPath(const std::shared_ptr& node) return "NotSupported"; } -void AurumXML::findObjects(std::vector> &ret, +void AurumXML::findXNodes(std::vector> &ret, std::string xpath, bool earlyReturn) { - createXMLtree(); - - LOGI("xpath %s earlyReturn %d", xpath.c_str(), earlyReturn); - try { - if (earlyReturn) { - xml_node node = mDoc->select_node(xpath.c_str()).node(); - const std::string id(node.attribute("id").value()); - if (mXNodeMap.count(id) > 0) ret.push_back(mXNodeMap[id]); + if (earlyReturn) { + xml_node node = mDoc->select_node(xpath.c_str()).node(); + const std::string id(node.attribute("id").value()); + if (mXNodeMap.count(id) > 0) ret.push_back(mXNodeMap[id]); + } else { + const auto nodes = mDoc->select_nodes(xpath.c_str()); - } else { - const auto nodes = mDoc->select_nodes(xpath.c_str()); + for (const auto& no : nodes) { + const std::string id(no.node().attribute("id").value()); - for (const auto& no : nodes) { - const std::string id(no.node().attribute("id").value()); + if (mXNodeMap.count(id) > 0) ret.push_back(mXNodeMap[id]); + } + } +} - if (mXNodeMap.count(id) > 0) ret.push_back(mXNodeMap[id]); - } +void AurumXML::findObjects(std::vector> &ret, + std::string xpath, bool earlyReturn) +{ + LOGI("xpath %s earlyReturn %d", xpath.c_str(), earlyReturn); + try { + findXNodes(ret, xpath, earlyReturn); + if (ret.size() == 0) { + createXMLtree(); + findXNodes(ret, xpath, earlyReturn); } } catch (const xpath_exception &e) { LOGI("findObjects Error: %s", e.what());