KFileMetaData

dublincoreextractor.cpp
1 /*
2  Helper class to extract XML encoded Dublin Core metadata
3 
4  Copyright (C) 2018 Stefan Brüns <[email protected]>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
21 #include "dublincoreextractor.h"
22 #include "extractionresult.h"
23 
24 namespace {
25 
26 inline QString dcNS() { return QStringLiteral("http://purl.org/dc/elements/1.1/"); }
27 inline QString dctermsNS() { return QStringLiteral("http://purl.org/dc/terms/"); }
28 
29 }
30 
31 namespace KFileMetaData
32 {
33 
34 void DublinCoreExtractor::extract(ExtractionResult* result, const QDomNode& fragment)
35 {
36  QDomElement e = fragment.firstChildElement();
37 
38  while (!e.isNull()) {
39  const QString namespaceURI = e.namespaceURI();
40  const QString localName = e.localName();
41 
42  // Dublin Core
43  // According to http://dublincore.org/documents/dces/, the
44  // properties should be treated the same regardless if
45  // used in the legacy DCES or DCMI-TERMS variant
46  if (namespaceURI == dcNS() || namespaceURI == dctermsNS()) {
47  if (localName == QLatin1String("description")) {
48  result->add(Property::Description, e.text());
49  } else if (localName == QLatin1String("subject")) {
50  result->add(Property::Subject, e.text());
51  } else if (localName == QLatin1String("title")) {
52  result->add(Property::Title, e.text());
53  } else if (localName == QLatin1String("creator")) {
54  result->add(Property::Author, e.text());
55  } else if (localName == QLatin1String("language")) {
56  result->add(Property::Language, e.text());
57  }
58  }
59  e = e.nextSiblingElement();
60  }
61 }
62 
63 } // namespace KFileMetaData
QString namespaceURI() const const
QDomElement nextSiblingElement(const QString &tagName) const const
QString localName() const const
QString text() const const
bool isNull() const const
QDomElement firstChildElement(const QString &tagName) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 30 2020 23:13:31 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.