File indexing completed on 2024-05-12 15:37:04

0001 /*
0002     Helper class to extract XML encoded Dublin Core metadata
0003 
0004     SPDX-FileCopyrightText: 2018 Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-or-later
0007 */
0008 
0009 #include "dublincoreextractor.h"
0010 #include "extractionresult.h"
0011 
0012 namespace {
0013 
0014 inline QString dcNS()      { return QStringLiteral("http://purl.org/dc/elements/1.1/"); }
0015 inline QString dctermsNS() { return QStringLiteral("http://purl.org/dc/terms/"); }
0016 
0017 }
0018 
0019 namespace KFileMetaData
0020 {
0021 
0022 void DublinCoreExtractor::extract(ExtractionResult* result, const QDomNode& fragment)
0023 {
0024     QDomElement e = fragment.firstChildElement();
0025 
0026     while (!e.isNull()) {
0027         const QString namespaceURI = e.namespaceURI();
0028         const QString localName = e.localName();
0029 
0030         // Dublin Core
0031         // According to http://dublincore.org/documents/dces/, the
0032         // properties should be treated the same regardless if
0033         // used in the legacy DCES or DCMI-TERMS variant
0034         if (namespaceURI == dcNS() || namespaceURI == dctermsNS()) {
0035             if (localName == QLatin1String("description")) {
0036                 result->add(Property::Description, e.text());
0037             } else if (localName == QLatin1String("subject")) {
0038                 result->add(Property::Subject, e.text());
0039             } else if (localName == QLatin1String("title")) {
0040                 result->add(Property::Title, e.text());
0041             } else if (localName == QLatin1String("creator")) {
0042                 result->add(Property::Author, e.text());
0043             } else if (localName == QLatin1String("language")) {
0044                 result->add(Property::Language, e.text());
0045             }
0046         }
0047         e = e.nextSiblingElement();
0048     }
0049 }
0050 
0051 } // namespace KFileMetaData