10 #include "NCLDocumentParser.h"
15 NCLDocumentParser::NCLDocumentParser(Project *project)
17 this->project = project;
20 NCLDocumentParser::~NCLDocumentParser()
27 return "NCLDocumentParser";
32 QString uri = project->getLocation();
34 QFile *file =
new QFile(uri,
this);
35 if (!file->open(QIODevice::ReadWrite)) {
36 qDebug() <<
"DocumentParser::parseDocument"
37 << tr(
"Could not open file %1\n").arg(uri);
43 QXmlInputSource inputSource(file);
44 QXmlSimpleReader reader;
45 reader.setContentHandler(
this);
46 reader.setErrorHandler(
this);
48 return reader.parse(inputSource);
53 QXmlInputSource inputSource;
54 inputSource.setData(str);
56 QXmlSimpleReader reader;
57 reader.setContentHandler(
this);
58 reader.setErrorHandler(
this);
60 return reader.parse(inputSource);
63 bool NCLDocumentParser::startElement(
const QString &,
66 const QXmlAttributes &attributes)
68 QMap<QString,QString> atts;
69 QString parentId = project->getUniqueId();
73 if(elementStack.size())
76 Entity *parentEntity = elementStack.top();
78 parentId = parentEntity->getUniqueId();
82 for (
int i=0 ;i < attributes.count(); i++)
83 atts[attributes.qName(i)] = attributes.value(i);
85 emit
addEntity(qName, parentId, atts,
false);
90 bool NCLDocumentParser::endElement(
const QString &namespaceURI,
91 const QString &localName,
95 if(elementStack.size())
102 bool NCLDocumentParser::characters(
const QString &)
107 bool NCLDocumentParser::endDocument()
109 emit parseFinished();
113 bool NCLDocumentParser::fatalError(
const QXmlParseException &exception)
115 qDebug() <<
"Fatal error on line" << exception.lineNumber()
116 <<
", column" << exception.columnNumber() <<
":"
117 << exception.message();
122 void NCLDocumentParser::onEntityAdded(QString , Entity *entity)
125 elementStack.push(entity);
129 void NCLDocumentParser::onEntityAddError(QString error)
131 qDebug() <<
"NCLDocumentParser::onEntityAddError(" << error <<
")";