Commit cc799cb6 authored by Ralf Habacker's avatar Ralf Habacker
Browse files

Add check for loading an unsupported xmi version

This helps to identify why zargo test cases cannot be loaded.

With this commit class UMLDoc gets a private class to hold loading errors
and Import_Argo::loadFromArgoFile returns error state in all cases.

CCBUG:56184
parent f70a6cc8
......@@ -45,27 +45,30 @@ bool Import_Argo::loadFromArgoFile(const KZip &zipFile, const QString &fileName)
QXmlStreamReader xml;
xml.addData(file->data());
bool result = true;
while (!xml.atEnd()) {
xml.readNext();
if (xml.name() == QLatin1String("member")) {
QXmlStreamAttributes attributes = xml.attributes();
QString type = attributes.value(QLatin1String("type")).toString();
QString name = attributes.value(QLatin1String("name")).toString();
if (type == QLatin1String("xmi"))
loadFromXMIFile(zipFile, name);
else if (type == QLatin1String("pgml"))
loadFromPGMLFile(zipFile, name);
else if (type == QLatin1String("todo"))
loadFromTodoFile(zipFile, name);
else
if (type == QLatin1String("xmi") && !loadFromXMIFile(zipFile, name))
result = false;
else if (type == QLatin1String("pgml") && !loadFromPGMLFile(zipFile, name))
result = false;
else if (type == QLatin1String("todo") && loadFromTodoFile(zipFile, name))
result = false;
else {
uError() << "unknown file type" << type << "in file" << zipFile.fileName() << ":" << fileName;
result = false;
}
}
}
if (xml.hasError()) {
reportError(xml, zipFile, fileName);
return false;
result = false;
}
return true;
return result;
}
bool Import_Argo::loadFromPGMLFile(const KZip &zipFile, const QString &fileName)
......
......@@ -93,11 +93,21 @@
DEBUG_REGISTER(UMLDoc)
class UMLDoc::Private
{
public:
UMLDoc *parent;
QStringList errors; ///< holds loading errors
Private(UMLDoc *p) : parent(p) {}
};
/**
* Constructor for the fileclass of the application.
*/
UMLDoc::UMLDoc()
: m_datatypeRoot(0),
: m_d(new Private(this)),
m_datatypeRoot(0),
m_stereoList(UMLStereotypeList()),
m_Name(i18n("UML Model")),
m_modelID("m1"),
......@@ -202,6 +212,7 @@ UMLDoc::~UMLDoc()
delete m_stereotypesModel;
delete m_diagramsModel;
delete m_objectsModel;
delete m_d;
}
/**
......@@ -500,6 +511,7 @@ bool UMLDoc::openDocument(const KUrl& url, const char* format /* =0 */)
// as it sets m_bLoading to false after it was temporarily
// changed to true to block recording of changes in redo-buffer
m_bLoading = true;
m_d->errors.clear();
#if QT_VERSION >= 0x050000
QTemporaryFile tmpfile;
tmpfile.open();
......@@ -729,12 +741,13 @@ bool UMLDoc::openDocument(const KUrl& url, const char* format /* =0 */)
m_bTypesAreResolved = true;
if (!status) {
#if QT_VERSION >= 0x050000
KMessageBox::error(0, i18n("There was a problem loading file: %1", url.toString()),
i18n("Load Error"));
QString msg = i18n("There was a problem loading file: %1", url.toString());
#else
KMessageBox::error(0, i18n("There was a problem loading file: %1", url.pathOrUrl()),
i18n("Load Error"));
QString msg = i18n("There was a problem loading file: %1", url.pathOrUrl());
#endif
if (m_d->errors.size() > 0)
msg += QLatin1String("<br/>") + i18n("Reason: %1", m_d->errors.join(QLatin1String("<br/>")));
KMessageBox::error(nullptr, msg, i18n("Load Error"));
newDocument();
return false;
}
......@@ -2339,6 +2352,15 @@ bool UMLDoc::loadFromXMI1(QIODevice & file, short encode)
return false;
}
QString versionString = root.attribute(QLatin1String("xmi.version"));
double version = versionString.toDouble();
if (version < 1.2) {
QString error = i18n("Unsupported xmi file version: %1", versionString);
m_d->errors << error;
DEBUG(DBG_SRC) << error;
return false;
}
m_nViewID = Uml::ID::None;
for (node = node.firstChild(); !node.isNull(); node = node.nextSibling()) {
if (node.isComment()) {
......@@ -2570,6 +2592,11 @@ ObjectsModel *UMLDoc::objectsModel()
return m_objectsModel;
}
void UMLDoc::setLoadingError(const QString &text)
{
m_d->errors << text;
}
StereotypesModel *UMLDoc::stereotypesModel()
{
return m_stereotypesModel;
......
......@@ -258,10 +258,15 @@ public:
StereotypesModel *stereotypesModel();
ObjectsModel *objectsModel();
void setLoadingError(const QString &text);
private:
void initSaveTimer();
void createDatatypeFolder();
class Private;
Private *m_d;
/**
* Array of predefined root folders.
*/
......
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