PropertyMapParser.cpp
Go to the documentation of this file.00001 #include "PropertyMapParser.h"
00002 #include "PropertyParser.h"
00003 #include "exception/XmlParseException.h"
00004
00005 #include <QtXml/QDomDocument>
00006 #include <QtXml/QDomNode>
00007 #include <QString>
00008 #include <QHash>
00009 #include <QtPlugin>
00010
00011 using namespace qic;
00012
00013 QVariant
00014 PropertyMapParser::parseProperty (const QDomNode & prop, QHash <QString, QObject *> & parser_map)
00015 {
00016 QDomElement e = prop.toElement();
00017 if (e.tagName() == "map")
00018 {
00019 QMap<QString, QVariant> map;
00020 for(QDomNode mn = e.firstChild(); !mn.isNull(); mn= mn.nextSibling())
00021 {
00022 QDomElement me = mn.toElement();
00023 if (me.tagName() == "entry")
00024 {
00025 QString key;
00026 QVariant val;
00027 for(QDomNode en = me.firstChild(); !en.isNull(); en= en.nextSibling())
00028 {
00029 QDomElement ee = en.toElement();
00030 if (ee.tagName() == "key")
00031 {
00032 key = ee.text();
00033 }
00034 else if (parser_map.contains(ee.tagName()))
00035 {
00036 QObject * parser_obj = parser_map[ee.tagName()];
00037 PropertyParser * parser = qobject_cast<PropertyParser *>(parser_obj);
00038 val = parser->parseProperty(en, parser_map);
00039 }
00040 else
00041 {
00042 throw XmlParseException (QString("No parser defined for %1.").arg(ee.tagName()));
00043 }
00044 }
00045 map.insert(key, val);
00046 }
00047 else
00048 {
00049 throw XmlParseException (QString("Expecting entry, %1 encountered.").arg(me.tagName()));
00050 }
00051 }
00052 return QVariant(map);
00053 }
00054 else
00055 {
00056 throw XmlParseException (QString("Expecting map, %1 encountered.").arg(e.tagName()));
00057 }
00058 }
00059
00060 Q_EXPORT_PLUGIN2(map_parser, PropertyMapParser)