From 24cfd3997d959d646bdc75ad5548d40f45d7733c Mon Sep 17 00:00:00 2001 From: Hosang Kim Date: Fri, 1 Apr 2022 17:27:04 +0900 Subject: [PATCH] AurumXML: add findObjects API for searching objects with XPath Change-Id: I26a6b44136ce3ac3ed666884437511cab17c9c0a --- libaurum/inc/AurumXML.h | 12 ++++++++++++ libaurum/src/AurumXML.cc | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/libaurum/inc/AurumXML.h b/libaurum/inc/AurumXML.h index a645b2c..e146ac0 100644 --- a/libaurum/inc/AurumXML.h +++ b/libaurum/inc/AurumXML.h @@ -73,6 +73,17 @@ public: */ std::string getXPath(std::string id); + /** + * @brief Finds that objects that satisfied with the xpath in the object tree. + * + * @param xpath + * + * @return the list of found AccessibleNode vector + * + * @since_tizen 7.0 + */ + std::vector> findObjects(std::string xpath); + private: /** * @internal @@ -106,6 +117,7 @@ private: xml_document *mDoc; std::shared_ptr mRoot; std::unordered_map mXPathMap; + std::unordered_map> mXNodeMap; }; } // namespace Aurum diff --git a/libaurum/src/AurumXML.cc b/libaurum/src/AurumXML.cc index 4fac7d2..c3da79b 100644 --- a/libaurum/src/AurumXML.cc +++ b/libaurum/src/AurumXML.cc @@ -42,6 +42,9 @@ void AurumXML::traverse(xml_node element, std::shared_ptr node) else name = node->getType(); + if (!name.compare("application")) + name = node->getPkg(); + // Remove white spaces. name.erase(remove(name.begin(), name.end(), ' '), name.end()); @@ -72,6 +75,8 @@ void AurumXML::traverse(xml_node element, std::shared_ptr node) element.append_attribute("visible") = node->isVisible(); element.append_attribute("selectable") = node->isSelectable(); + mXNodeMap[node->getId()] = node; + int childCnt = node->getChildCount(); for (int i = 0; i < childCnt; i++) { std::shared_ptr childNode = node->getChildAt(i); @@ -180,4 +185,20 @@ std::string AurumXML::getXPath(std::string id) } return "NotSupported"; +} + +std::vector> AurumXML::findObjects(std::string xpath) +{ + std::vector> ret; + xpath_node_set results = mDoc->select_nodes(xpath.c_str()); + + for (xpath_node_set::const_iterator it = results.begin(); it != results.end(); ++it) + { + auto node = (*it).node(); + std::string id(node.attribute("id").value()); + + if (mXNodeMap.count(id) > 0) ret.push_back(mXNodeMap[id]); + } + + return ret; } \ No newline at end of file -- 2.7.4