KFileMetaData

dublincoreextractor.cpp
1 /*
2  Helper class to extract XML encoded Dublin Core metadata
3 
4  SPDX-FileCopyrightText: 2018 Stefan BrĂ¼ns <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.1-or-later
7 */
8 
9 #include "dublincoreextractor.h"
10 #include "extractionresult.h"
11 
12 namespace {
13 
14 inline QString dcNS() { return QStringLiteral("http://purl.org/dc/elements/1.1/"); }
15 inline QString dctermsNS() { return QStringLiteral("http://purl.org/dc/terms/"); }
16 
17 }
18 
19 namespace KFileMetaData
20 {
21 
22 void DublinCoreExtractor::extract(ExtractionResult* result, const QDomNode& fragment)
23 {
24  QDomElement e = fragment.firstChildElement();
25 
26  while (!e.isNull()) {
27  const QString namespaceURI = e.namespaceURI();
28  const QString localName = e.localName();
29 
30  // Dublin Core
31  // According to http://dublincore.org/documents/dces/, the
32  // properties should be treated the same regardless if
33  // used in the legacy DCES or DCMI-TERMS variant
34  if (namespaceURI == dcNS() || namespaceURI == dctermsNS()) {
35  if (localName == QLatin1String("description")) {
36  result->add(Property::Description, e.text());
37  } else if (localName == QLatin1String("subject")) {
38  result->add(Property::Subject, e.text());
39  } else if (localName == QLatin1String("title")) {
40  result->add(Property::Title, e.text());
41  } else if (localName == QLatin1String("creator")) {
42  result->add(Property::Author, e.text());
43  } else if (localName == QLatin1String("language")) {
44  result->add(Property::Language, e.text());
45  }
46  }
47  e = e.nextSiblingElement();
48  }
49 }
50 
51 } // namespace KFileMetaData
QString text() const const
bool isNull() const const
QString namespaceURI() const const
QString localName() const const
QDomElement nextSiblingElement(const QString &tagName) const const
QDomElement firstChildElement(const QString &tagName) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu May 26 2022 03:46:07 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.