AurumXML: add findObjects API for searching objects with XPath 56/273256/2
authorHosang Kim <hosang12.kim@samsung.com>
Fri, 1 Apr 2022 08:27:04 +0000 (17:27 +0900)
committerHosang Kim <hosang12.kim@samsung.com>
Mon, 4 Apr 2022 06:56:38 +0000 (15:56 +0900)
Change-Id: I26a6b44136ce3ac3ed666884437511cab17c9c0a

libaurum/inc/AurumXML.h
libaurum/src/AurumXML.cc

index a645b2c3ed8e7796fd57aa1edd8cd5649e97918f..e146ac0f3bfe4a1e6328c07fcd93ddc75531115b 100644 (file)
@@ -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<std::shared_ptr<AccessibleNode>> findObjects(std::string xpath);
+
 private:
     /**
      * @internal
@@ -106,6 +117,7 @@ private:
     xml_document                                *mDoc;
     std::shared_ptr<AccessibleNode>              mRoot;
     std::unordered_map<std::string, std::string> mXPathMap;
+    std::unordered_map<std::string, std::shared_ptr<AccessibleNode>> mXNodeMap;
 };
 }  // namespace Aurum
 
index 4fac7d2a1b9a6bfc31be11573029c2f05d8e6e0a..c3da79b13de66be45835c0243c2eec8ca84333b9 100644 (file)
@@ -42,6 +42,9 @@ void AurumXML::traverse(xml_node element, std::shared_ptr<AccessibleNode> 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<AccessibleNode> 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<AccessibleNode> childNode = node->getChildAt(i);
@@ -180,4 +185,20 @@ std::string AurumXML::getXPath(std::string id)
     }
 
     return "NotSupported";
+}
+
+std::vector<std::shared_ptr<AccessibleNode>> AurumXML::findObjects(std::string xpath)
+{
+    std::vector<std::shared_ptr<AccessibleNode>> 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