-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfox_xmlsession.cpp
80 lines (65 loc) · 2.34 KB
/
fox_xmlsession.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// Transform a doc word document to xml
// to get only target propriety no image or other
// Author: Peter Hohl <[email protected]>, 24.10.2013
// http://www.freeroad.ch/
// Copyright: See COPYING file that comes with this distribution
#include "fox_xmlsession.h"
using namespace FOX;
XmlSession *XmlSession::theInstance;
XmlSession* XmlSession::self() {
if (!theInstance) {
theInstance = new XmlSession();
}
return theInstance;
}
QDomDocument XmlSession::doc() {
return wv2dom;
}
XmlSession::XmlSession() {
this->base_header();
cur_len = -1;
}
void XmlSession::base_header() {
QDomProcessingInstruction header = wv2dom.createProcessingInstruction("xml", QString("version=\"1.0\" encoding=\"utf-8\""));
wv2dom.appendChild(header);
DCroot = wv2dom.createElement(NSPREFIXDOC + QString("root"));
DCroot.setAttribute("xmlns:fox", "http://xmlgraphics.apache.org/fop/extensions");
DCroot.setAttribute("xmlns:cms", "http://www.freeroad.ch/2013/CMSFormat");
DCroot.setAttribute("xmlns:svg", "http://www.w3.org/2000/svg");
DCroot.setAttribute("xmlns:fo", "http://www.w3.org/1999/XSL/Format");
wv2dom.appendChild(DCroot);
//// XMLBEEP() << " header: " << wv2dom.toString(5);
}
void XmlSession::report(const QString msg, const int position) {
QDomElement head = XmlSession::self()->doc().documentElement().firstChild().toElement();
if (!head.isNull() && reportonxml == 1) {
QDomElement error = wv2dom.createElement(NSPREFIXDOC + QString("error"));
error.setAttribute("line", position);
error.setAttribute("msg", msg);
head.appendChild(error);
}
}
XmlSession::~XmlSession() {
}
QDomText XmlSession::createTextNode(const QString txt) {
return wv2dom.createTextNode(txt);
}
QDomElement XmlSession::createtag(const QString tagname) {
QDomElement htag;
if (tagname.length() > 1) {
cur_len++;
QString part = tagname.mid(0, 2);
part.append("-");
part.append(QString::number(cur_len));
htag = wv2dom.createElement(NSPREFIXDOC + tagname);
htag.setAttribute("id", part);
}
return htag;
}
QDomElement XmlSession::createDtext(const QString txt, const QString tagname) {
QDomElement rnode = this->createtag(tagname);
QDomText liatext = this->createTextNode(txt);
rnode.appendChild(liatext);
return rnode;
}