• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeaccessibility API Reference
  • KDE Home
  • Contact Us
 

jovie

  • sources
  • kde-4.12
  • kdeaccessibility
  • jovie
  • filters
  • xhtml2ssml
xhtml2ssml.cpp
Go to the documentation of this file.
1 /****************************************************************************
2  XHTMLToSSMLParser class
3 
4  Parses a piece of XHTML markup and converts into SSML.
5  -------------------
6  Copyright 2004 by Paul Giannaros <ceruleanblaze@gmail.com>
7  -------------------
8  Original author: Paul Giannaros <ceruleanblaze@gmail.com>
9 
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) version 3.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23  ***************************************************************************/
24 
25 #include "xhtml2ssml.h"
26 
27 #include <QtXml/QXmlAttributes>
28 #include <QtCore/QFile>
29 #include <QtCore/QTextStream>
30 
31 #include <iostream>
32 
33 #include "xmlelement.h"
34 
36 bool XHTMLToSSMLParser::startDocument() {
38  QFile file("tagmappingrc");
39  if(!file.open(QIODevice::ReadOnly)) {
40  std::cerr << "Could not read config file 'tagmappingrc'. Please check that it exists and is readable.\n";
41  // Kill further parsing
42  return false;
43  }
44  QTextStream stream(&file);
45  // File parsing.
46  bool linestatus = true;
47  while(!stream.atEnd()) {
48  linestatus = readFileConfigEntry(stream.readLine());
49  // If there's some syntactical error in the file then return false.
50  if(!linestatus)
51  return false;
53  }
54  return true;
55 }
56 
57 bool XHTMLToSSMLParser::startElement(const QString &, const QString &, const QString &qName, const QXmlAttributes &atts) {
58  QString attributes = "";
59  if(atts.length() > 0) {
60  const int attsLength = atts.length();
61  for(int i = 0; i < attsLength; ++i)
62  attributes += " " + atts.qName(i) + "=\"" + atts.value(i) + "\"";
63  }
64  QString fromelement = qName + attributes;
65  // If this element is one of the keys that was specified in the configuration file, get what it should be converted to and
66  // append to the output string.
67  QString toelement = m_xhtml2ssml[fromelement];
68  if(toelement)
69  m_output.append(XMLElement::fromQString(toelement).startTag());
70  return true;
71 }
72 
73 bool XHTMLToSSMLParser::endElement(const QString &, const QString &, const QString &qName) {
74  QString fromelement = qName;
75  QString toelement = m_xhtml2ssml[fromelement];
76  if(toelement)
77  m_output.append(XMLElement::fromQString(toelement).endTag());
78  return true;
79 }
80 
81 bool XHTMLToSSMLParser::characters(const QString &characters) {
82  m_output.append(characters);
83  return true;
84 }
85 
86 
87 QString XHTMLToSSMLParser::convertedText() {
88  return m_output.simplified();
89 }
90 
95 bool XHTMLToSSMLParser::readFileConfigEntry(const QString &line) {
96  // comments
97  if(line.trimmed().startsWith('#')) {
98  return true;
99  }
100  // break into QStringList
101  // the second parameter to split is the string, with all space simplified and all space around the : removed, i.e
102  // "something : somethingelse" -> "something:somethingelse"
103  QStringList keyvalue = QString( ':').replace(':').split( ':', line.simplified().replace(' :', ':'));
104  if(keyvalue.count() != 2)
105  return false;
106  m_xhtml2ssml[keyvalue[0]] = keyvalue[1];
107  return true;
108 }
XHTMLToSSMLParser::startElement
bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts)
start of an element encountered ()
Definition: xhtml2ssml.cpp:57
XHTMLToSSMLParser::characters
bool characters(const QString &)
text encountered (blah bah blah)
Definition: xhtml2ssml.cpp:81
XHTMLToSSMLParser::startDocument
bool startDocument()
No need to reimplement constructor.
Definition: xhtml2ssml.cpp:36
XHTMLToSSMLParser::convertedText
QString convertedText()
Get the output text that was generated during the parsing.
Definition: xhtml2ssml.cpp:87
XHTMLToSSMLParser::endElement
bool endElement(const QString &namespaceURI, const QString &localName, const QString &qName)
end of an element encountered ()
Definition: xhtml2ssml.cpp:73
xhtml2ssml.h
XMLElement::fromQString
static XMLElement fromQString(const QString &str)
Create an XMLElement from a QString.
Definition: xmlelement.cpp:87
xmlelement.h
XHTMLToSSMLParser::readFileConfigEntry
bool readFileConfigEntry(const QString &line)
Parse a line from the configuration file which maps xhtml : ssml equivalent.
Definition: xhtml2ssml.cpp:95
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:32:25 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

jovie

Skip menu "jovie"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeaccessibility API Reference

Skip menu "kdeaccessibility API Reference"
  • jovie

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal