Commit 4309be72 authored by Volker Krause's avatar Volker Krause
Browse files

Complete ExtractorRepository API for the new extractor types

This should enable KItinerary Workbench being ported to the new API.
parent afd35c3c
......@@ -26,10 +26,17 @@ private Q_SLOTS:
void testReload()
{
ExtractorRepository repo;
const auto count = repo.allExtractors().size();
const auto count = repo.extractors().size();
QVERIFY(count > 0);
QVERIFY(repo.extractorByName(u"<IATA BCBP>"));
QVERIFY(repo.extractorByName(u"chaos-communication-congress"));
QVERIFY(!repo.extractorByName(u"I-DONT-EXIST"));
repo.reload();
QCOMPARE(repo.allExtractors().size(), count);
QCOMPARE(repo.extractors().size(), count);
QVERIFY(repo.extractorByName(u"<IATA BCBP>"));
QVERIFY(repo.extractorByName(u"chaos-communication-congress"));
QVERIFY(!repo.extractorByName(u"I-DONT-EXIST"));
}
void testApplyFilter()
......
......@@ -17,6 +17,7 @@
#include <KItinerary/JsonLdDocument>
#include <KItinerary/MergeUtil>
#include <KItinerary/Reservation>
#include <KItinerary/ScriptExtractor>
#include <KCalendarCore/Event>
#include <KCalendarCore/ICalFormat>
......@@ -77,12 +78,14 @@ static void printCapabilities()
static void printExtractors()
{
ExtractorRepository repo;
for (const auto &ext : repo.allExtractors()) {
std::cout << qPrintable(ext.name()) << " (" << qPrintable(ext.mimeType());
if (!ext.scriptFileName().isEmpty()) {
std::cout << ", " << qPrintable(ext.scriptFileName()) << ":" << qPrintable(ext.scriptFunction());
for (const auto &ext : repo.extractors()) {
std::cout << qPrintable(ext->name());
if (auto scriptExt = dynamic_cast<const ScriptExtractor*>(ext.get())) {
std::cout << " (" << qPrintable(scriptExt->mimeType()) << ", "
<< qPrintable(scriptExt->scriptFileName()) << ":"
<< qPrintable(scriptExt->scriptFunction()) << ")";
}
std::cout << ")" << std::endl;
std::cout << std::endl;
}
}
......
......@@ -116,6 +116,11 @@ void ExtractorRepository::reload()
d->loadAll();
}
const std::vector<std::unique_ptr<AbstractExtractor>>& ExtractorRepository::extractors() const
{
return d->m_extractorsNew;
}
const std::vector<Extractor>& ExtractorRepository::allExtractors() const
{
return d->m_extractors;
......@@ -283,6 +288,17 @@ void ExtractorRepository::extractorsForContent(const QString &content, std::vect
d->extractorForTypeAndContent(ExtractorInput::Text, content, extractors);
}
const AbstractExtractor* ExtractorRepository::extractorByName(QStringView name) const
{
auto it = std::lower_bound(d->m_extractorsNew.begin(), d->m_extractorsNew.end(), name, [](const auto &lhs, auto rhs) {
return lhs->name() < rhs;
});
if (it != d->m_extractorsNew.end() && (*it)->name() == name) {
return (*it).get();
}
return {};
}
Extractor ExtractorRepository::extractor(const QString &name) const
{
auto it = std::lower_bound(d->m_extractors.begin(), d->m_extractors.end(), name, [](const auto &lhs, const auto &rhs) {
......
......@@ -59,27 +59,29 @@ public:
void reload();
/** All known extractors. */
const std::vector<Extractor>& allExtractors() const;
const std::vector<std::unique_ptr<AbstractExtractor>>& extractors() const;
[[deprecated("use extractors()")]] const std::vector<Extractor>& allExtractors() const;
/** Finds matching extractors for the given document node. */
void extractorsForNode(const ExtractorDocumentNode &node, std::vector<const AbstractExtractor*> &extractors) const;
/** Finds matching extractors for the given message part. */
void extractorsForMessage(KMime::Content *part, std::vector<Extractor> &extractors) const;
[[deprecated("use extractorsForNode")]] void extractorsForMessage(KMime::Content *part, std::vector<Extractor> &extractors) const;
/** Finds matching extractors for the given pkpass boarding pass. */
void extractorsForPass(KPkPass::Pass *pass, std::vector<Extractor> &extractors) const;
[[deprecated("use extractorsForNode")]] void extractorsForPass(KPkPass::Pass *pass, std::vector<Extractor> &extractors) const;
/** Finds matching extractors for the given JSON-LD data provided by generic extractors. */
void extractorsForJsonLd(const QJsonArray &data, std::vector<Extractor> &extractors) const;
[[deprecated("use extractorsForNode")]] void extractorsForJsonLd(const QJsonArray &data, std::vector<Extractor> &extractors) const;
/** Finds matching extractors for the given barcode string. */
void extractorsForBarcode(const QString &code, std::vector<Extractor> &extractors) const;
[[deprecated("use extractorsForNode")]] void extractorsForBarcode(const QString &code, std::vector<Extractor> &extractors) const;
/** Find matching extractors for the given iCal calendar. */
void extractorsForCalendar(const KCalendarCore::Calendar *cal, std::vector<Extractor> &extractors) const;
[[deprecated("use extractorsForNode")]] void extractorsForCalendar(const KCalendarCore::Calendar *cal, std::vector<Extractor> &extractors) const;
/** Find matching extractors for the given iCal event. */
void extractorsForEvent(const KCalendarCore::Event *event, std::vector<Extractor> &extractors) const;
[[deprecated("use extractorsForNode")]] void extractorsForEvent(const KCalendarCore::Event *event, std::vector<Extractor> &extractors) const;
/** Find matching extractors for the given content. */
void extractorsForContent(const QString &content, std::vector<Extractor> &extractors) const;
[[deprecated("use extractorsForNode")]] void extractorsForContent(const QString &content, std::vector<Extractor> &extractors) const;
/** Returns the extractor with the given identifier. */
Extractor extractor(const QString &name) const;
const AbstractExtractor* extractorByName(QStringView name) const;
[[deprecated("use extractorByName")]] Extractor extractor(const QString &name) const;
/** Returns the list of additional search paths for extractor scripts. */
QStringList additionalSearchPaths() const;
......
......@@ -8,7 +8,6 @@
#include <kitinerary_version.h>
#include "extractorcapabilities.h"
#include "extractor.h"
#include <KItinerary/ExtractorRepository>
......@@ -70,11 +69,11 @@ QString ExtractorCapabilities::capabilitiesString()
#endif
"\n"
"Extractor scripts : ";
"Extractors : ";
auto caps = QString::fromLatin1(s);
ExtractorRepository repo;
caps += QString::number(repo.allExtractors().size()) + QLatin1Char('\n');
caps += QString::number(repo.extractors().size()) + QLatin1Char('\n');
return caps;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment