Commit e1f32a18 authored by Volker Krause's avatar Volker Krause
Browse files

Add document processor for IATA BCBPs

This will replace the existing extractor, and allows directly exposing
IATA BCBP objects to extractor scripts and filters.
parent bcccb1d9
......@@ -29,12 +29,13 @@
"childNodes": [
{
"childNodes": [
"[...]"
],
"content": "M1DRAGON/KONQUI EXXX007 VIEMXPAK 1996 249J013C0042 167>5321WW8325BAK 0014123456002001414246700100141234789012A0141234567890 1AK AK 1234567890123 4PCYLX58Z^108ABCDEFGH",
"contextDateTime": "Mon Aug 19 20:23:28 2019 GMT+0200",
"isNull": false,
"location": 0,
"mimeType": "text/plain",
"mimeType": "application/octet-stream",
"result": [
]
}
......
......@@ -69,6 +69,7 @@ set(kitinerary_lib_srcs
processors/binarydocumentprocessor.cpp
processors/externalprocessor.cpp
processors/htmldocumentprocessor.cpp
processors/iatabcbpdocumentprocessor.cpp
processors/icaldocumentprocessor.cpp
processors/imagedocumentprocessor.cpp
processors/jsonlddocumentprocessor.cpp
......
......@@ -12,6 +12,7 @@
#include "processors/binarydocumentprocessor.h"
#include "processors/externalprocessor.h"
#include "processors/htmldocumentprocessor.h"
#include "processors/iatabcbpdocumentprocessor.h"
#include "processors/icaldocumentprocessor.h"
#include "processors/imagedocumentprocessor.h"
#include "processors/jsonlddocumentprocessor.h"
......@@ -115,6 +116,7 @@ void ExtractorDocumentNodeFactoryStatic::registerBuiltIn()
registerProcessor<IcalEventProcessor>(u"internal/event");
registerProcessor<ImageDocumentProcessor>(u"internal/qimage", {u"image/png"});
registerProcessor<SsbDocumentProcessor>(u"internal/era-ssb");
registerProcessor<IataBcbpDocumentProcessor>(u"internal/iata-bcbp");
registerProcessor<Uic9183DocumentProcessor>(u"internal/uic9183");
registerProcessor<VdvDocumentProcessor>(u"internal/vdv");
registerProcessor<IcalCalendarProcessor>(u"text/calendar");
......
/*
SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "iatabcbpdocumentprocessor.h"
#include <iata/iatabcbp.h>
#include <iata/iatabcbpparser.h>
#include <KItinerary/ExtractorResult>
using namespace KItinerary;
bool IataBcbpDocumentProcessor::canHandleData(const QByteArray &encodedData, [[maybe_unused]] QStringView fileName) const
{
return IataBcbp::maybeIataBcbp(encodedData);
}
ExtractorDocumentNode IataBcbpDocumentProcessor::createNodeFromData(const QByteArray &encodedData) const
{
ExtractorDocumentNode node;
IataBcbp ticket(QString::fromUtf8(encodedData));
if (ticket.isValid()) {
node.setContent(ticket);
}
return node;
}
void IataBcbpDocumentProcessor::preExtract(ExtractorDocumentNode &node, [[maybe_unused]] const ExtractorEngine *engine) const
{
const auto bcbp = node.content<IataBcbp>();
node.addResult(IataBcbpParser::parse(bcbp, node.contextDateTime().date()));
}
/*
SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KITINERARY_IATABCBPDOCUMENTPROCESSOR_H
#define KITINERARY_IATABCBPDOCUMENTPROCESSOR_H
#include <KItinerary/ExtractorDocumentProcessor>
namespace KItinerary {
/** Document node processor for IATA BCBPs. */
class IataBcbpDocumentProcessor : public ExtractorDocumentProcessor
{
public:
bool canHandleData(const QByteArray &encodedData, QStringView fileName) const override;
ExtractorDocumentNode createNodeFromData(const QByteArray &encodedData) const override;
void preExtract(ExtractorDocumentNode &node, const ExtractorEngine *engine) const override;
};
}
#endif // KITINERARY_IATABCBPDOCUMENTPROCESSOR_H
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