SVN_SILENT made messages (.desktop file)
[kdeaccessibility.git] / ksayit / src / saxhandler.cpp
blob3c83505e1f60403aa0ab412884265ec201ed0cc1
1 //
2 // C++ Implementation: saxhandler
3 //
4 // Description:
5 //
6 //
7 // Author: Robert Vogl <voglrobe@web.de>, (C) 2005
8 //
9 // Copyright: See COPYING file that comes with this distribution
12 // #include <iostream> // cout
13 // using namespace std;
15 // KDE includes
16 #include <kdebug.h>
17 #include <klocale.h>
18 #include <kmessagebox.h>
20 // App specific includes
21 #include "saxhandler.h"
23 SaxHandler::SaxHandler()
24 : QXmlDefaultHandler()
26 m_output.clear();
27 m_rtf = true;
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)
73 m_rtf = rtf;
77 bool SaxHandler::startElement(const QString &,
78 const QString &,
79 const QString & qName,
80 const QXmlAttributes & atts )
82 if ( !m_rtf )
83 return true;
85 QString tag = qName.toLower();
87 TagMapT::iterator it;
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 + ">";
95 return true;
99 bool SaxHandler::endElement(const QString &,
100 const QString &,
101 const QString & qName)
103 if ( !m_rtf )
104 return true;
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) + ">";
116 return true;
120 bool SaxHandler::characters(const QString & ch)
122 m_output += ch;
123 return true;
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") );
132 return false;
136 bool SaxHandler::resolveEntity(const QString &publicId,
137 const QString &systemId,
138 QXmlInputSource* &ret)
140 return true;
144 bool SaxHandler::externalEntityDecl(const QString & name,
145 const QString & publicId,
146 const QString & systemId)
148 kDebug(100200) << "externalEntityDecl(): " << name << ", " << publicId << ", " << systemId << endl;
149 return true;
153 bool SaxHandler::internalEntityDecl(const QString & name,
154 const QString & value)
156 kDebug() << "internalEntityDecl(): " << name << ", " << value << endl;
157 return true;
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.");
167 int res;
168 // TODO: "Option: don't show again this warning."
169 res = KMessageBox::warningContinueCancel(0, warn, i18n("Parser problem") );
170 if ( res == KMessageBox::Cancel )
171 return false;
172 return true;
176 void SaxHandler::getData( QString &data ) const
178 data = m_output;
182 void SaxHandler::reset()
184 m_output.clear();