]> git.sven.stormbind.net Git - sven/vym.git/blob - xml-base.cpp
3cd9428db985d5f127c2e544a247cb1a0d99ea7d
[sven/vym.git] / xml-base.cpp
1 #include "xml-base.h"
2
3 #include "vymmodel.h"
4
5 parseBaseHandler::parseBaseHandler() {}
6
7 parseBaseHandler::~parseBaseHandler() {}
8
9 QString parseBaseHandler::errorProtocol() { return errorProt; }
10
11
12 QString parseBaseHandler::parseHREF(QString href)
13 {
14     QString type=href.section(":",0,0);
15     QString path=href.section(":",1,1);
16     if (!tmpDir.endsWith("/"))
17         return tmpDir + "/" + path;
18     else    
19         return tmpDir + path;
20 }
21
22 bool parseBaseHandler::fatalError( const QXmlParseException& exception ) 
23 {
24     errorProt += QString( "Fatal parsing error: %1 in line %2, column %3\n")
25         .arg( exception.message() )
26         .arg( exception.lineNumber() )
27         .arg( exception.columnNumber() );
28     // Try to read the bogus line
29     errorProt += QString("File is: %1\n").arg(inputFile);
30     if (!inputFile.isEmpty() )
31     {   // Input was from file
32         if (!loadStringFromDisk (inputFile, inputString))
33         {
34             qWarning()<<"parseBaseHandler::fatalError Couldn't read from "<<inputFile;
35             return QXmlDefaultHandler::fatalError( exception );
36         }
37     }
38     QString s;
39     QStringList sl = inputString.split ("\n");
40     int i = 1;
41     QStringList::Iterator it = sl.begin();
42     while (i < exception.lineNumber())
43     {
44         it++;
45         i++;
46     }
47     s =*it;
48     s.insert (exception.columnNumber()-1,"<ERROR>");
49     errorProt += s;
50     return QXmlDefaultHandler::fatalError( exception );
51 }
52
53 void parseBaseHandler::setModel (VymModel *m)
54 {
55     model=m;
56 }
57
58 void parseBaseHandler::setTmpDir (QString tp)
59 {
60     tmpDir=tp;
61 }
62
63 void parseBaseHandler::setInputFile (const QString &s)
64 {
65     inputFile = s;
66 }
67
68 void parseBaseHandler::setInputString ( const QString &s)
69 {
70     inputString = s;
71 }
72
73 void parseBaseHandler::setLoadMode (const LoadMode &lm, int p)
74 {
75     loadMode=lm;
76     insertPos=p;
77 }
78
79 bool parseBaseHandler::readHtmlAttr (const QXmlAttributes& a)
80 {
81     for (int i=1; i<=a.count(); i++)
82         htmldata+=" "+a.localName(i-1)+"=\""+a.value(i-1)+"\"";
83     return true;
84 }
85
86