Extract propfind tag xml node processing into separate method
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Thu, 20 Apr 2023 12:53:48 +0000 (20:53 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Tue, 16 May 2023 10:23:33 +0000 (18:23 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/libsync/networkjobs.cpp
src/libsync/networkjobs.h

index d7baf9f28a07579cc5376f03d724e1fa730b0947..d858d5320b708067fe03bf522a25d9459277a7c5 100644 (file)
@@ -663,25 +663,8 @@ QVariantMap PropfindJob::processPropfindDomDocument(const QDomDocument &domDocum
                 const auto propChildElementTagName = propChildElement.tagName();
 
                 if (propChildElementTagName == propfindFileTagsContainerElementTagName) {
-                    const auto tagNodes = domDocument.elementsByTagName(propfindFileTagElementTagName);
-                    const auto tagCount = tagNodes.count();
-
-                    auto tagList = QStringList();
-                    tagList.reserve(tagCount);
-
-                    for (auto i = 0; i < tagCount; ++i) {
-                        const auto tagNode = tagNodes.at(i);
-                        const auto tagElement = tagNode.toElement();
-
-                        if (tagElement.isNull()) {
-                            continue;
-                        }
-
-                        tagList.append(tagElement.text());
-                    }
-
+                    const auto tagList = processTagsInPropfindDomDocument(domDocument);
                     items.insert(propChildElementTagName, tagList);
-
                 } else {
                     items.insert(propChildElementTagName, propChildElement.text());
                 }
@@ -694,6 +677,31 @@ QVariantMap PropfindJob::processPropfindDomDocument(const QDomDocument &domDocum
     return items;
 }
 
+QStringList PropfindJob::processTagsInPropfindDomDocument(const QDomDocument &domDocument)
+{
+    const auto tagNodes = domDocument.elementsByTagName(propfindFileTagElementTagName);
+    if (tagNodes.isEmpty()) {
+        return {};
+    }
+
+    const auto tagCount = tagNodes.count();
+    auto tagList = QStringList();
+    tagList.reserve(tagCount);
+
+    for (auto i = 0; i < tagCount; ++i) {
+        const auto tagNode = tagNodes.at(i);
+        const auto tagElement = tagNode.toElement();
+
+        if (tagElement.isNull()) {
+            continue;
+        }
+
+        tagList.append(tagElement.text());
+    }
+
+    return tagList;
+}
+
 /*********************************************************************************************/
 
 #ifndef TOKEN_AUTH_ONLY
index c274b4d3f13e43aaff9e8ebfa2dc057caf9f7213..11f3c26ac7901493fa867e4dc488187e47e5ef28 100644 (file)
@@ -200,6 +200,7 @@ private slots:
 
 private:
     static QVariantMap processPropfindDomDocument(const QDomDocument &domDocument);
+    static QStringList processTagsInPropfindDomDocument(const QDomDocument &domDocument);
 
     QList<QByteArray> _properties;
 };