shared: processors: Use DocumentProcessResult instead of PageData vector
This commit is contained in:
父節點
e68706b8d6
當前提交
9a2ef19308
@ -24,7 +24,9 @@ QString DefaultTextProcessor::processText(const QByteArray &data) const
|
||||
return {};
|
||||
}
|
||||
|
||||
QVector<PageData> DefaultTextProcessor::process(const QByteArray &data) const
|
||||
DocumentProcessResult DefaultTextProcessor::process(const QByteArray &data) const
|
||||
{
|
||||
return {{0, processText(data)}};
|
||||
DocumentProcessResult result;
|
||||
result.pages.append({0, processText(data)});
|
||||
return result;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ class DefaultTextProcessor : public Processor
|
||||
public:
|
||||
DefaultTextProcessor();
|
||||
QString processText(const QByteArray &data) const;
|
||||
QVector<PageData> process(const QByteArray &data) const override;
|
||||
DocumentProcessResult process(const QByteArray &data) const override;
|
||||
};
|
||||
|
||||
#endif // DEFAULTTEXTPROCESSOR_H
|
||||
|
@ -10,7 +10,7 @@ class NothingProcessor : public Processor
|
||||
NothingProcessor();
|
||||
|
||||
public:
|
||||
QVector<PageData> process(const QByteArray & /*data*/) const override
|
||||
DocumentProcessResult process(const QByteArray & /*data*/) const override
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
@ -3,12 +3,12 @@
|
||||
#include "odtprocessor.h"
|
||||
#include "tagstripperprocessor.h"
|
||||
|
||||
QVector<PageData> OdtProcessor::process(const QByteArray & /*data*/) const
|
||||
DocumentProcessResult OdtProcessor::process(const QByteArray & /*data*/) const
|
||||
{
|
||||
throw LooqsGeneralException("Not implemented yet");
|
||||
}
|
||||
|
||||
QVector<PageData> OdtProcessor::process(QString path) const
|
||||
DocumentProcessResult OdtProcessor::process(QString path) const
|
||||
{
|
||||
QuaZipFile zipFile(path);
|
||||
zipFile.setFileName("content.xml");
|
||||
|
@ -8,9 +8,9 @@ class OdtProcessor : public Processor
|
||||
{
|
||||
this->PREFERED_DATA_SOURCE = FILEPATH;
|
||||
}
|
||||
QVector<PageData> process(const QByteArray &data) const override;
|
||||
DocumentProcessResult process(const QByteArray &data) const override;
|
||||
|
||||
QVector<PageData> process(QString path) const override;
|
||||
DocumentProcessResult process(QString path) const override;
|
||||
};
|
||||
|
||||
#endif // ODTPROCESSOR_H
|
||||
|
@ -2,8 +2,8 @@
|
||||
#define PROCESSOR_H
|
||||
#include <QVector>
|
||||
#include <QFile>
|
||||
#include "pagedata.h"
|
||||
#include "utils.h"
|
||||
#include "documentprocessresult.h"
|
||||
enum DataSource
|
||||
{
|
||||
FILEPATH,
|
||||
@ -18,8 +18,8 @@ class Processor
|
||||
* a single file */
|
||||
DataSource PREFERED_DATA_SOURCE = ARRAY;
|
||||
Processor();
|
||||
virtual QVector<PageData> process(const QByteArray &data) const = 0;
|
||||
virtual QVector<PageData> process(QString path) const
|
||||
virtual DocumentProcessResult process(const QByteArray &data) const = 0;
|
||||
virtual DocumentProcessResult process(QString path) const
|
||||
{
|
||||
return process(Utils::readFile(path));
|
||||
}
|
||||
|
@ -65,18 +65,12 @@ void SandboxedProcessor::enableSandbox(QString readablePath)
|
||||
exile_free_policy(policy);
|
||||
}
|
||||
|
||||
void SandboxedProcessor::printResults(const QVector<PageData> &pageData)
|
||||
void SandboxedProcessor::printResults(const DocumentProcessResult &result)
|
||||
{
|
||||
QFile fsstdout;
|
||||
fsstdout.open(stdout, QIODevice::WriteOnly);
|
||||
QDataStream stream(&fsstdout);
|
||||
|
||||
for(const PageData &data : pageData)
|
||||
{
|
||||
stream << data;
|
||||
// fsstdout.flush();
|
||||
}
|
||||
|
||||
stream << result;
|
||||
fsstdout.close();
|
||||
}
|
||||
|
||||
@ -102,7 +96,7 @@ SaveFileResult SandboxedProcessor::process()
|
||||
return OK;
|
||||
}
|
||||
|
||||
QVector<PageData> pageData;
|
||||
DocumentProcessResult processResult;
|
||||
QString absPath = fileInfo.absoluteFilePath();
|
||||
|
||||
try
|
||||
@ -111,13 +105,13 @@ SaveFileResult SandboxedProcessor::process()
|
||||
{
|
||||
/* Read access to FS needed... doh..*/
|
||||
enableSandbox(absPath);
|
||||
pageData = processor->process(absPath);
|
||||
processResult = processor->process(absPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
QByteArray data = Utils::readFile(absPath);
|
||||
enableSandbox();
|
||||
pageData = processor->process(data);
|
||||
processResult = processor->process(data);
|
||||
}
|
||||
}
|
||||
catch(LooqsGeneralException &e)
|
||||
@ -126,6 +120,6 @@ SaveFileResult SandboxedProcessor::process()
|
||||
return PROCESSFAIL;
|
||||
}
|
||||
|
||||
printResults(pageData);
|
||||
return pageData.isEmpty() ? OK_WASEMPTY : OK;
|
||||
printResults(processResult);
|
||||
return processResult.pages.isEmpty() ? OK_WASEMPTY : OK;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define SANDBOXEDPROCESSOR_H
|
||||
#include <QString>
|
||||
#include <QMimeDatabase>
|
||||
#include "pagedata.h"
|
||||
#include "documentprocessresult.h"
|
||||
#include "savefileresult.h"
|
||||
|
||||
class SandboxedProcessor
|
||||
@ -12,7 +12,7 @@ class SandboxedProcessor
|
||||
QMimeDatabase mimeDatabase;
|
||||
|
||||
void enableSandbox(QString readablePath = "");
|
||||
void printResults(const QVector<PageData> &pageData);
|
||||
void printResults(const DocumentProcessResult &pageData);
|
||||
|
||||
public:
|
||||
SandboxedProcessor(QString filepath)
|
||||
|
@ -4,11 +4,11 @@ TagStripperProcessor::TagStripperProcessor()
|
||||
{
|
||||
}
|
||||
|
||||
QVector<PageData> TagStripperProcessor::process(const QByteArray &data) const
|
||||
DocumentProcessResult TagStripperProcessor::process(const QByteArray &data) const
|
||||
{
|
||||
auto result = DefaultTextProcessor::process(data);
|
||||
// TODO: does not work properly with <br> and does not deal with entities...
|
||||
|
||||
result[0].content.remove(QRegExp("<[^>]*>"));
|
||||
Q_ASSERT(result.pages.size() > 0);
|
||||
result.pages[0].content.remove(QRegExp("<[^>]*>"));
|
||||
return result;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ class TagStripperProcessor : public DefaultTextProcessor
|
||||
TagStripperProcessor();
|
||||
|
||||
public:
|
||||
QVector<PageData> process(const QByteArray &data) const override;
|
||||
DocumentProcessResult process(const QByteArray &data) const override;
|
||||
};
|
||||
|
||||
#endif // XMLSTRIPPERPROCESSOR_H
|
||||
|
Loading…
Reference in New Issue
Block a user