| 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 | |
| 14 | namespace { |
| 15 | |
| 16 | inline QString dcNS() { return QStringLiteral("http://purl.org/dc/elements/1.1/" ); } |
| 17 | inline QString dctermsNS() { return QStringLiteral("http://purl.org/dc/terms/" ); } |
| 18 | |
| 19 | } |
| 20 | |
| 21 | namespace KFileMetaData |
| 22 | { |
| 23 | |
| 24 | void DublinCoreExtractor::(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: Property::Description, value: e.text()); |
| 45 | } else if (localName == QLatin1String("subject" )) { |
| 46 | result->add(property: Property::Subject, value: e.text()); |
| 47 | } else if (localName == QLatin1String("title" )) { |
| 48 | result->add(property: Property::Title, value: e.text()); |
| 49 | } else if (localName == QLatin1String("creator" )) { |
| 50 | result->add(property: Property::Author, value: e.text()); |
| 51 | } else if (localName == QLatin1String("created" )) { |
| 52 | QDateTime dt = Parser::dateTimeFromString(dateString: e.text()); |
| 53 | result->add(property: Property::CreationDate, value: dt); |
| 54 | } else if (localName == QLatin1String("language" )) { |
| 55 | result->add(property: Property::Language, value: e.text()); |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | } // namespace KFileMetaData |
| 61 | |