GUI: Determine the XML report format before reading report.
This commit is contained in:
parent
299e200d45
commit
0f0f53f919
|
@ -244,7 +244,22 @@ void ResultsView::DisableProgressbar()
|
||||||
|
|
||||||
void ResultsView::ReadErrorsXml(const QString &filename)
|
void ResultsView::ReadErrorsXml(const QString &filename)
|
||||||
{
|
{
|
||||||
XmlReportV1 *report = new XmlReportV1(filename, this);
|
const int version = XmlReport::determineVersion(filename);
|
||||||
|
if (version == 0)
|
||||||
|
{
|
||||||
|
QMessageBox msgBox;
|
||||||
|
msgBox.setText(tr("Failed to read the report."));
|
||||||
|
msgBox.setIcon(QMessageBox::Critical);
|
||||||
|
msgBox.exec();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
XmlReport *report = NULL;
|
||||||
|
if (version == 1)
|
||||||
|
report = new XmlReportV1(filename, this);
|
||||||
|
else if (version == 2)
|
||||||
|
report = new XmlReportV2(filename, this);
|
||||||
|
|
||||||
QList<ErrorLine> errors;
|
QList<ErrorLine> errors;
|
||||||
if (report)
|
if (report)
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,9 +18,13 @@
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QXmlStreamReader>
|
||||||
#include "report.h"
|
#include "report.h"
|
||||||
#include "xmlreport.h"
|
#include "xmlreport.h"
|
||||||
|
|
||||||
|
static const char ResultElementName[] = "results";
|
||||||
|
static const char VersionAttribute[] = "version";
|
||||||
|
|
||||||
XmlReport::XmlReport(const QString &filename, QObject * parent) :
|
XmlReport::XmlReport(const QString &filename, QObject * parent) :
|
||||||
Report(filename, parent)
|
Report(filename, parent)
|
||||||
|
@ -37,3 +41,47 @@ QString XmlReport::quoteMessage(const QString &message)
|
||||||
quotedMessage.replace(">", ">");
|
quotedMessage.replace(">", ">");
|
||||||
return quotedMessage;
|
return quotedMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int XmlReport::determineVersion(const QString &filename)
|
||||||
|
{
|
||||||
|
QFile file;
|
||||||
|
file.setFileName(filename);
|
||||||
|
bool succeed = file.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||||
|
if (!succeed)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
QXmlStreamReader reader(&file);
|
||||||
|
while (!reader.atEnd())
|
||||||
|
{
|
||||||
|
switch (reader.readNext())
|
||||||
|
{
|
||||||
|
case QXmlStreamReader::StartElement:
|
||||||
|
if (reader.name() == ResultElementName)
|
||||||
|
{
|
||||||
|
QXmlStreamAttributes attribs = reader.attributes();
|
||||||
|
if (attribs.hasAttribute(QString(VersionAttribute)))
|
||||||
|
{
|
||||||
|
int ver = attribs.value("", VersionAttribute).toString().toInt();
|
||||||
|
return ver;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Not handled
|
||||||
|
case QXmlStreamReader::EndElement:
|
||||||
|
case QXmlStreamReader::NoToken:
|
||||||
|
case QXmlStreamReader::Invalid:
|
||||||
|
case QXmlStreamReader::StartDocument:
|
||||||
|
case QXmlStreamReader::EndDocument:
|
||||||
|
case QXmlStreamReader::Characters:
|
||||||
|
case QXmlStreamReader::Comment:
|
||||||
|
case QXmlStreamReader::DTD:
|
||||||
|
case QXmlStreamReader::EntityReference:
|
||||||
|
case QXmlStreamReader::ProcessingInstruction:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#define XML_REPORT_H
|
#define XML_REPORT_H
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QList>
|
||||||
#include "report.h"
|
#include "report.h"
|
||||||
|
|
||||||
class QObject;
|
class QObject;
|
||||||
|
@ -36,12 +37,24 @@ class XmlReport : public Report
|
||||||
public:
|
public:
|
||||||
XmlReport(const QString &filename, QObject * parent = 0);
|
XmlReport(const QString &filename, QObject * parent = 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Read contents of the report file.
|
||||||
|
*/
|
||||||
|
virtual QList<ErrorLine> Read() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Quote the message.
|
* @brief Quote the message.
|
||||||
* @param message Message to quote.
|
* @param message Message to quote.
|
||||||
* @return quoted message.
|
* @return quoted message.
|
||||||
*/
|
*/
|
||||||
static QString quoteMessage(const QString &message);
|
static QString quoteMessage(const QString &message);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the XML report format version from the file.
|
||||||
|
* @param filename Filename of the report file.
|
||||||
|
* @return XML report format version or 0 if error happened.
|
||||||
|
*/
|
||||||
|
static int determineVersion(const QString &filename);
|
||||||
};
|
};
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ static const char VersionAttribute[] = "version";
|
||||||
static const char VerboseAttribute[] = "verbose";
|
static const char VerboseAttribute[] = "verbose";
|
||||||
|
|
||||||
XmlReportV2::XmlReportV2(const QString &filename, QObject * parent) :
|
XmlReportV2::XmlReportV2(const QString &filename, QObject * parent) :
|
||||||
Report(filename, parent),
|
XmlReport(filename, parent),
|
||||||
mXmlReader(NULL),
|
mXmlReader(NULL),
|
||||||
mXmlWriter(NULL)
|
mXmlWriter(NULL)
|
||||||
{
|
{
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
* This report outputs XML-formatted report. The XML format must match command
|
* This report outputs XML-formatted report. The XML format must match command
|
||||||
* line version's XML output.
|
* line version's XML output.
|
||||||
*/
|
*/
|
||||||
class XmlReportV2 : public Report
|
class XmlReportV2 : public XmlReport
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
XmlReportV2(const QString &filename, QObject * parent = 0);
|
XmlReportV2(const QString &filename, QObject * parent = 0);
|
||||||
|
|
Loading…
Reference in New Issue