8#include "xmlextractor.h"
9#include "kfilemetadata_debug.h"
10#include "dublincoreextractor.h"
12#include <QDomDocument>
14#include <QXmlStreamReader>
16#ifdef SVG_XML_COMPRESSED_SUPPORT
17#include <KCompressionDevice>
23inline QString svgNS() {
return QStringLiteral(
"http://www.w3.org/2000/svg"); }
24inline QString rdfNS() {
return QStringLiteral(
"http://www.w3.org/1999/02/22-rdf-syntax-ns#"); }
25inline QString ccNS() {
return QStringLiteral(
"http://creativecommons.org/ns#"); }
37 extractSvgText(result, e);
40 qCDebug(KFILEMETADATA_LOG) << node.
text();
46 QStringLiteral(
"application/xml"),
47 QStringLiteral(
"image/svg+xml"),
48 QStringLiteral(
"image/svg+xml-compressed"),
49 QStringLiteral(
"image/svg"),
57XmlExtractor::XmlExtractor(
QObject* parent)
58 : ExtractorPlugin(parent)
65 return supportedMimeTypes;
68void XmlExtractor::extract(ExtractionResult* result)
70 auto flags = result->inputFlags();
72 QFile file(result->inputUrl());
74 qCWarning(KFILEMETADATA_LOG) <<
"Document is not a valid file";
79 if ((result->inputMimetype() ==
QLatin1String(
"image/svg")) ||
80 (result->inputMimetype() ==
QLatin1String(
"image/svg+xml-compressed")) ||
81 (result->inputMimetype() ==
QLatin1String(
"image/svg+xml"))) {
83 result->addType(Type::Image);
86#ifdef SVG_XML_COMPRESSED_SUPPORT
87 std::unique_ptr<KCompressionDevice> gzReader;
88 if (result->inputMimetype() ==
QLatin1String(
"image/svg+xml-compressed")) {
89 gzReader.reset(
new KCompressionDevice(&file,
false, KCompressionDevice::CompressionType::GZip));
93 ioDevice = gzReader.get();
96 if (result->inputMimetype() ==
QLatin1String(
"image/svg+xml-compressed")) {
102 const bool processNamespaces =
true;
117 if (!(flags & ExtractionResult::ExtractMetaData)) {
122 if (rdf.isNull() || rdf.namespaceURI() != rdfNS()) {
127 if (cc.isNull() || cc.namespaceURI() != ccNS()) {
131 DublinCoreExtractor::extract(result, cc);
136 }
else if (flags & ExtractionResult::ExtractPlainText) {
138 extractSvgText(result, e);
143 result->addType(Type::Text);
145 if (flags & ExtractionResult::ExtractPlainText) {
147 while (!stream.atEnd()) {
153 result->append(text);
163#include "moc_xmlextractor.cpp"
ParseResult setContent(QAnyStringView text, ParseOptions options)
QString text() const const
QDomElement firstChildElement(const QString &tagName, const QString &namespaceURI) const const
bool isNull() const const
QString localName() const const
QString namespaceURI() const const
QDomElement nextSiblingElement(const QString &tagName, const QString &namespaceURI) const const
bool isEmpty() const const
QString trimmed() const const