2 // C++ Implementation: saxhandler
7 // Author: Robert Vogl <voglrobe@web.de>, (C) 2005
9 // Copyright: See COPYING file that comes with this distribution
12 // #include <iostream> // cout
13 // using namespace std;
18 #include <kmessagebox.h>
20 // App specific includes
21 #include "saxhandler.h"
23 SaxHandler::SaxHandler()
24 : QXmlDefaultHandler()
28 m_tagmap
["action"] = "B";
29 m_tagmap
["application"] = "B";
30 m_tagmap
["function"] = "B";
31 m_tagmap
["guibutton"] = "B";
32 m_tagmap
["guiicon"] = "B";
33 m_tagmap
["guilabel"] = "B";
34 m_tagmap
["guimenu"] = "B";
35 m_tagmap
["guimenuitem"] = "B";
36 m_tagmap
["guisubmenu"] = "B";
37 m_tagmap
["menuchoice"] = "B";
38 m_tagmap
["mousebutton"] = "B";
39 m_tagmap
["option"] = "B";
40 m_tagmap
["author"] = "B";
41 m_tagmap
["corpauthor"] = "B";
42 m_tagmap
["warning"] = "FONT color=\"red\"";
43 m_tagmap
["command"] = "TT";
44 m_tagmap
["email"] = "TT";
45 m_tagmap
["filename"] = "TT";
46 m_tagmap
["keycap"] = "TT";
47 m_tagmap
["keycode"] = "TT";
48 m_tagmap
["keycombo"] = "TT";
49 m_tagmap
["keysym"] = "TT";
50 m_tagmap
["link"] = "TT";
51 m_tagmap
["literal"] = "TT";
52 m_tagmap
["userinput"] = "TT";
53 m_tagmap
["citation"] = "EM";
54 m_tagmap
["emphasis"] = "EM";
55 m_tagmap
["foreignphrase"] = "EM";
56 m_tagmap
["phrase"] = "EM";
57 m_tagmap
["comment"] = "EM";
58 m_tagmap
["note"] = "EM";
59 m_tagmap
["tip"] = "EM";
60 m_tagmap
["subscript"] = "small";
61 m_tagmap
["superscript"] = "small";
62 m_tagmap
["itemizedlist"] = "UL";
63 m_tagmap
["listitem"] = "LI";
66 SaxHandler::~SaxHandler()
71 void SaxHandler::setRTF(bool rtf
)
77 bool SaxHandler::startElement(const QString
&,
79 const QString
& qName
,
80 const QXmlAttributes
& atts
)
85 QString tag
= qName
.toLower();
88 it
= m_tagmap
.find(tag
);
89 if ( it
!= m_tagmap
.end() ){
90 // tag found in hash table
91 QString rtftag
= (*it
).second
;
92 m_output
+= "<" + rtftag
+ ">";
99 bool SaxHandler::endElement(const QString
&,
101 const QString
& qName
)
106 QString tag
= qName
.toLower();
108 TagMapT::iterator it
;
109 it
= m_tagmap
.find(tag
);
110 if ( it
!= m_tagmap
.end() ){
111 // tag found in hash table
112 QString rtftag
= (*it
).second
;
113 m_output
+= "</" + rtftag
.section(" ", 0, 0) + ">";
120 bool SaxHandler::characters(const QString
& ch
)
127 bool SaxHandler::fatalError(const QXmlParseException
&exc
)
129 QString err
= i18n("Fatal error while parsing XML-Paragraph:\n");
130 err
+= i18n("%1, Line: %2", exc
.message(), exc
.lineNumber());
131 KMessageBox::error(0, err
, i18n("Fatal error") );
136 bool SaxHandler::resolveEntity(const QString
&publicId
,
137 const QString
&systemId
,
138 QXmlInputSource
* &ret
)
144 bool SaxHandler::externalEntityDecl(const QString
& name
,
145 const QString
& publicId
,
146 const QString
& systemId
)
148 kDebug(100200) << "externalEntityDecl(): " << name
<< ", " << publicId
<< ", " << systemId
<< endl
;
153 bool SaxHandler::internalEntityDecl(const QString
& name
,
154 const QString
& value
)
156 kDebug() << "internalEntityDecl(): " << name
<< ", " << value
<< endl
;
161 bool SaxHandler::skippedEntity(const QString
&name
)
163 QString warn
= i18n("Unresolved entity found: %1.\n", name
);
164 warn
+= i18n("KSayIt does not support DocBook files with external entities. ");
165 warn
+= i18n("Parsing can continue, but the resulting text will contain gaps.");
168 // TODO: "Option: don't show again this warning."
169 res
= KMessageBox::warningContinueCancel(0, warn
, i18n("Parser problem") );
170 if ( res
== KMessageBox::Cancel
)
176 void SaxHandler::getData( QString
&data
) const
182 void SaxHandler::reset()