2009-06-24 09:54:56 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2011-01-09 20:33:36 +01:00
|
|
|
* Copyright (C) 2007-2011 Daniel Marjamäki and Cppcheck team.
|
2009-06-24 09:54:56 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-09-27 17:08:31 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-06-24 09:54:56 +02:00
|
|
|
*/
|
|
|
|
|
2010-10-31 12:16:55 +01:00
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
2011-02-05 11:12:34 +01:00
|
|
|
#include <QFile>
|
|
|
|
#include <QXmlStreamReader>
|
2010-10-31 12:16:55 +01:00
|
|
|
#include "report.h"
|
2009-06-24 09:54:56 +02:00
|
|
|
#include "xmlreport.h"
|
|
|
|
|
2011-02-05 11:12:34 +01:00
|
|
|
static const char ResultElementName[] = "results";
|
|
|
|
static const char VersionAttribute[] = "version";
|
2010-07-10 15:37:36 +02:00
|
|
|
|
2009-06-24 09:54:56 +02:00
|
|
|
XmlReport::XmlReport(const QString &filename, QObject * parent) :
|
2011-02-04 22:56:14 +01:00
|
|
|
Report(filename, parent)
|
2009-06-24 09:54:56 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-02-04 23:23:25 +01:00
|
|
|
QString XmlReport::quoteMessage(const QString &message)
|
|
|
|
{
|
|
|
|
QString quotedMessage(message);
|
|
|
|
quotedMessage.replace("&", "&");
|
|
|
|
quotedMessage.replace("\"", """);
|
|
|
|
quotedMessage.replace("'", "'");
|
|
|
|
quotedMessage.replace("<", "<");
|
|
|
|
quotedMessage.replace(">", ">");
|
|
|
|
return quotedMessage;
|
|
|
|
}
|
2011-02-05 11:12:34 +01:00
|
|
|
|
2011-02-05 15:07:59 +01:00
|
|
|
QString XmlReport::unquoteMessage(const QString &message)
|
|
|
|
{
|
|
|
|
QString quotedMessage(message);
|
|
|
|
quotedMessage.replace("&", "&");
|
|
|
|
quotedMessage.replace(""", "\"");
|
|
|
|
quotedMessage.replace("'", "'");
|
|
|
|
quotedMessage.replace("<", "<");
|
|
|
|
quotedMessage.replace(">", ">");
|
|
|
|
return quotedMessage;
|
|
|
|
}
|
|
|
|
|
2011-02-05 11:12:34 +01:00
|
|
|
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);
|
2011-10-13 20:53:06 +02:00
|
|
|
while (!reader.atEnd()) {
|
|
|
|
switch (reader.readNext()) {
|
2011-02-05 11:12:34 +01:00
|
|
|
case QXmlStreamReader::StartElement:
|
2011-10-13 20:53:06 +02:00
|
|
|
if (reader.name() == ResultElementName) {
|
2011-02-05 11:12:34 +01:00
|
|
|
QXmlStreamAttributes attribs = reader.attributes();
|
2011-10-13 20:53:06 +02:00
|
|
|
if (attribs.hasAttribute(QString(VersionAttribute))) {
|
2011-02-05 11:12:34 +01:00
|
|
|
int ver = attribs.value("", VersionAttribute).toString().toInt();
|
|
|
|
return ver;
|
2011-10-13 20:53:06 +02:00
|
|
|
} else
|
2011-02-05 11:12:34 +01:00
|
|
|
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;
|
|
|
|
}
|