*
* @since_tizen 7.0
*/
- std::vector<std::shared_ptr<AccessibleNode>> findObjects(std::string xpath);
+ std::vector<std::shared_ptr<AccessibleNode>> findObjects(std::string xpath, bool earlyReturn = false);
private:
/**
*/
std::string getOptimalXPath(xml_document *doc, xml_node node);
+ /**
+ * @internal
+ *
+ * @brief Check xml_node exists or not
+ *
+ * @param string id
+ *
+ * @return xml_node
+ *
+ * @since_tizen 7.0
+ */
+ xml_node checkNode(std::string id);
+
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
else
name = node->getType();
- if (!name.compare("application"))
- name = node->getPkg();
+ if (!name.compare("application")) name = node->getPkg();
// Remove white spaces.
name.erase(remove(name.begin(), name.end(), ' '), name.end());
return getOptimalXPath(doc, parent).append(xpath);
}
-std::string AurumXML::getXPath(std::string id)
+std::string makeQuery(std::string id)
{
- if (mXPathMap.count(id) > 0) return mXPathMap[id];
-
std::string query;
query += "//*[@id=\"";
query += id;
query += "\"]";
- try {
- auto node = mDoc->select_node(query.c_str()).node();
+ return query;
+}
- if (!node) createXMLtree();
+xml_node AurumXML::checkNode(std::string id)
+{
+ xml_node node;
+ try {
+ std::string query = makeQuery(id);
+ node = mDoc->select_node(query.c_str()).node();
- if (node) {
- std::string xpath = getOptimalXPath(mDoc, node);
- mXPathMap[id] = xpath;
- return xpath;
+ if (!node) {
+ createXMLtree();
+ node = mDoc->select_node(query.c_str()).node();
}
-
} catch (const xpath_exception &e) {
LOGI("getXPath Error: %s", e.what());
}
+ return node;
+}
+
+std::string AurumXML::getXPath(std::string id)
+{
+ xml_node node = checkNode(id);
+
+ if (node) {
+ std::string xpath = getOptimalXPath(mDoc, node);
+ return xpath;
+ }
return "NotSupported";
}
-std::vector<std::shared_ptr<AccessibleNode>> AurumXML::findObjects(std::string xpath)
+std::vector<std::shared_ptr<AccessibleNode>> AurumXML::findObjects(
+ std::string xpath, bool earlyReturn)
{
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());
+ createXMLtree();
+
+ LOGI("xpath %s earlyReturn %d", xpath.c_str(), earlyReturn);
+ try {
+ if (earlyReturn) {
+ xml_node node = mDoc->select_node(xpath.c_str()).node();
+ std::string id(node.attribute("id").value());
+ if (mXNodeMap.count(id) > 0) ret.push_back(mXNodeMap[id]);
+
+ } else {
+ xpath_node_set results = mDoc->select_nodes(xpath.c_str());
- if (mXNodeMap.count(id) > 0) ret.push_back(mXNodeMap[id]);
+ 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]);
+ }
+ }
+ } catch (const xpath_exception &e) {
+ LOGI("findObjects Error: %s", e.what());
}
return ret;
-}
\ No newline at end of file
+}