KFileMetaData

dublincoreextractor.cpp
1/*
2 Helper class to extract XML encoded Dublin Core metadata
3
4 SPDX-FileCopyrightText: 2018 Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de>
5
6 SPDX-License-Identifier: LGPL-2.1-or-later
7*/
8
9#include "dublincoreextractor.h"
10#include "extractionresult.h"
11
12#include "datetimeparser_p.h"
13
14namespace {
15
16inline QString dcNS() { return QStringLiteral("http://purl.org/dc/elements/1.1/"); }
17inline QString dctermsNS() { return QStringLiteral("http://purl.org/dc/terms/"); }
18
19}
20
21namespace KFileMetaData
22{
23
24void DublinCoreExtractor::extract(ExtractionResult* result, const QDomNode& fragment)
25{
26
27 for (auto e = fragment.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) {
28 // Dublin Core
29 // According to http://dublincore.org/documents/dces/, the
30 // properties should be treated the same regardless if
31 // used in the legacy DCES or DCMI-TERMS variant
32
33 const QString namespaceURI = e.namespaceURI();
34 if (namespaceURI != dcNS() && namespaceURI != dctermsNS()) {
35 continue;
36 }
37
38 if (e.text().isEmpty()) {
39 continue;
40 }
41
42 const QString localName = e.localName();
43 if (localName == QLatin1String("description")) {
44 result->add(Property::Description, e.text());
45 } else if (localName == QLatin1String("subject")) {
46 result->add(Property::Subject, e.text());
47 } else if (localName == QLatin1String("title")) {
48 result->add(Property::Title, e.text());
49 } else if (localName == QLatin1String("creator")) {
50 result->add(Property::Author, e.text());
51 } else if (localName == QLatin1String("created")) {
52 QDateTime dt = Parser::dateTimeFromString(e.text());
53 result->add(Property::CreationDate, dt);
54 } else if (localName == QLatin1String("language")) {
55 result->add(Property::Language, e.text());
56 }
57 }
58}
59
60} // namespace KFileMetaData
@ Subject
Refers to the subject of the file.
Definition properties.h:127
@ Title
Refers to the Title of the content of the file.
Definition properties.h:121
@ Author
The Author field indicated the primary creator of a document.
Definition properties.h:114
@ Description
Represents the description stored in the file.
Definition properties.h:351
@ CreationDate
The date the content of the file was created.
Definition properties.h:177
@ Language
The language the document is written in.
Definition properties.h:159
The KFileMetaData namespace.
QDomElement firstChildElement(const QString &tagName, const QString &namespaceURI) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:49:15 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.