X-Git-Url: https://git.sven.stormbind.net/?a=blobdiff_plain;f=src%2Fxml-base.cpp;fp=src%2Fxml-base.cpp;h=3345f25be952e15ff60b0a567aaf33c5df855704;hb=d483bd8e6523c23c6f1d8908a2e0611c2bc9ff4f;hp=0000000000000000000000000000000000000000;hpb=7dfa3fe589d1722d49681f42cdb0bf1e6efb5223;p=sven%2Fvym.git diff --git a/src/xml-base.cpp b/src/xml-base.cpp new file mode 100644 index 0000000..3345f25 --- /dev/null +++ b/src/xml-base.cpp @@ -0,0 +1,69 @@ +#include "xml-base.h" + +#include "vymmodel.h" + +parseBaseHandler::parseBaseHandler() {} + +parseBaseHandler::~parseBaseHandler() {} + +QString parseBaseHandler::errorProtocol() { return errorProt; } + +QString parseBaseHandler::parseHREF(QString href) +{ + QString type = href.section(":", 0, 0); + QString path = href.section(":", 1, 1); + if (!tmpDir.endsWith("/")) + return tmpDir + "/" + path; + else + return tmpDir + path; +} + +bool parseBaseHandler::fatalError(const QXmlParseException &exception) +{ + errorProt += QString("Fatal parsing error: %1 in line %2, column %3\n") + .arg(exception.message()) + .arg(exception.lineNumber()) + .arg(exception.columnNumber()); + // Try to read the bogus line + errorProt += QString("File is: %1\n").arg(inputFile); + if (!inputFile.isEmpty()) { // Input was from file + if (!loadStringFromDisk(inputFile, inputString)) { + qWarning() << "parseBaseHandler::fatalError Couldn't read from " + << inputFile; + return QXmlDefaultHandler::fatalError(exception); + } + } + QString s; + QStringList sl = inputString.split("\n"); + int i = 1; + QStringList::Iterator it = sl.begin(); + while (i < exception.lineNumber()) { + it++; + i++; + } + s = *it; + s.insert(exception.columnNumber() - 1, ""); + errorProt += s; + return QXmlDefaultHandler::fatalError(exception); +} + +void parseBaseHandler::setModel(VymModel *m) { model = m; } + +void parseBaseHandler::setTmpDir(QString tp) { tmpDir = tp; } + +void parseBaseHandler::setInputFile(const QString &s) { inputFile = s; } + +void parseBaseHandler::setInputString(const QString &s) { inputString = s; } + +void parseBaseHandler::setLoadMode(const LoadMode &lm, int p) +{ + loadMode = lm; + insertPos = p; +} + +bool parseBaseHandler::readHtmlAttr(const QXmlAttributes &a) +{ + for (int i = 1; i <= a.count(); i++) + htmldata += " " + a.localName(i - 1) + "=\"" + a.value(i - 1) + "\""; + return true; +}