From 00bb99ac80741fc50ef8a289719373032f2391eb Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeaccessibility@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kttsd/filters/xhtml2ssml/Doxyfile | 266 +++++++++++++++++++++++ kttsd/filters/xhtml2ssml/demonstration.html | 5 + kttsd/filters/xhtml2ssml/main.cpp | 22 ++ kttsd/filters/xhtml2ssml/tagmappingrc | 5 + kttsd/filters/xhtml2ssml/xhtml2ssml.cpp | 105 +++++++++ kttsd/filters/xhtml2ssml/xhtml2ssml.h | 61 ++++++ kttsd/filters/xhtml2ssml/xhtml2ssml.kdevelop | 112 ++++++++++ kttsd/filters/xhtml2ssml/xhtml2ssml.kdevelop.pcs | Bin 0 -> 14766 bytes kttsd/filters/xhtml2ssml/xhtml2ssml.kdevses | 38 ++++ kttsd/filters/xhtml2ssml/xhtml2ssml.pro | 10 + kttsd/filters/xhtml2ssml/xmlelement.cpp | 102 +++++++++ kttsd/filters/xhtml2ssml/xmlelement.h | 91 ++++++++ 12 files changed, 817 insertions(+) create mode 100644 kttsd/filters/xhtml2ssml/Doxyfile create mode 100644 kttsd/filters/xhtml2ssml/demonstration.html create mode 100644 kttsd/filters/xhtml2ssml/main.cpp create mode 100644 kttsd/filters/xhtml2ssml/tagmappingrc create mode 100644 kttsd/filters/xhtml2ssml/xhtml2ssml.cpp create mode 100644 kttsd/filters/xhtml2ssml/xhtml2ssml.h create mode 100644 kttsd/filters/xhtml2ssml/xhtml2ssml.kdevelop create mode 100644 kttsd/filters/xhtml2ssml/xhtml2ssml.kdevelop.pcs create mode 100644 kttsd/filters/xhtml2ssml/xhtml2ssml.kdevses create mode 100644 kttsd/filters/xhtml2ssml/xhtml2ssml.pro create mode 100644 kttsd/filters/xhtml2ssml/xmlelement.cpp create mode 100644 kttsd/filters/xhtml2ssml/xmlelement.h (limited to 'kttsd/filters/xhtml2ssml') diff --git a/kttsd/filters/xhtml2ssml/Doxyfile b/kttsd/filters/xhtml2ssml/Doxyfile new file mode 100644 index 0000000..0061358 --- /dev/null +++ b/kttsd/filters/xhtml2ssml/Doxyfile @@ -0,0 +1,266 @@ +# Doxyfile 1.3.7-KDevelop + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +PROJECT_NAME = xhtml2ssml.kdevelop +PROJECT_NUMBER = $VERSION$ +OUTPUT_DIRECTORY = +CREATE_SUBDIRS = NO +OUTPUT_LANGUAGE = English +USE_WINDOWS_ENCODING = NO +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = YES +STRIP_FROM_PATH = /home/paul/ +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = NO +MULTILINE_CPP_IS_BRIEF = NO +DETAILS_AT_TOP = NO +INHERIT_DOCS = YES +DISTRIBUTE_GROUP_DOC = NO +TAB_SIZE = 8 +ALIASES = +OPTIMIZE_OUTPUT_FOR_C = NO +OPTIMIZE_OUTPUT_JAVA = NO +SUBGROUPING = YES +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +EXTRACT_ALL = NO +EXTRACT_PRIVATE = NO +EXTRACT_STATIC = NO +EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_METHODS = NO +HIDE_UNDOC_MEMBERS = NO +HIDE_UNDOC_CLASSES = NO +HIDE_FRIEND_COMPOUNDS = NO +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = YES +HIDE_SCOPE_NAMES = NO +SHOW_INCLUDE_FILES = YES +INLINE_INFO = YES +SORT_MEMBER_DOCS = YES +SORT_BRIEF_DOCS = NO +SORT_BY_SCOPE_NAME = NO +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST= YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = NO +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_IF_DOC_ERROR = YES +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = /home/paul/Kdecvs/kdeaccessibility/kttsd/filters +FILE_PATTERNS = *.c \ + *.cc \ + *.cxx \ + *.cpp \ + *.c++ \ + *.java \ + *.ii \ + *.ixx \ + *.ipp \ + *.i++ \ + *.inl \ + *.h \ + *.hh \ + *.hxx \ + *.hpp \ + *.h++ \ + *.idl \ + *.odl \ + *.cs \ + *.php \ + *.php3 \ + *.inc \ + *.m \ + *.mm \ + *.C \ + *.CC \ + *.C++ \ + *.II \ + *.I++ \ + *.H \ + *.HH \ + *.H++ \ + *.CS \ + *.PHP \ + *.PHP3 \ + *.M \ + *.MM \ + *.C \ + *.H \ + *.tlh \ + *.diff \ + *.patch \ + *.moc \ + *.xpm \ + *.dox +RECURSIVE = yes +EXCLUDE = +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = +EXAMPLE_PATH = +EXAMPLE_PATTERNS = * +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = +INPUT_FILTER = +FILTER_SOURCE_FILES = NO +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- +SOURCE_BROWSER = NO +INLINE_SOURCES = NO +STRIP_CODE_COMMENTS = YES +REFERENCED_BY_RELATION = YES +REFERENCES_RELATION = YES +VERBATIM_HEADERS = YES +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = NO +COLS_IN_ALPHA_INDEX = 5 +IGNORE_PREFIX = +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = html +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = +HTML_STYLESHEET = +HTML_ALIGN_MEMBERS = YES +GENERATE_HTMLHELP = NO +CHM_FILE = +HHC_LOCATION = +GENERATE_CHI = NO +BINARY_TOC = NO +TOC_EXPAND = NO +DISABLE_INDEX = NO +ENUM_VALUES_PER_LINE = 4 +GENERATE_TREEVIEW = NO +TREEVIEW_WIDTH = 250 +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = YES +LATEX_OUTPUT = latex +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = NO +PAPER_TYPE = a4wide +EXTRA_PACKAGES = +LATEX_HEADER = +PDF_HYPERLINKS = NO +USE_PDFLATEX = NO +LATEX_BATCHMODE = NO +LATEX_HIDE_INDICES = NO +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = rtf +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = NO +MAN_OUTPUT = man +MAN_EXTENSION = .3 +MAN_LINKS = NO +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- +GENERATE_XML = yes +XML_OUTPUT = xml +XML_SCHEMA = +XML_DTD = +XML_PROGRAMLISTING = YES +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- +GENERATE_AUTOGEN_DEF = NO +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = NO +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = +PREDEFINED = +EXPAND_AS_DEFINED = +SKIP_FUNCTION_MACROS = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- +TAGFILES = +GENERATE_TAGFILE = xhtml2ssml.tag +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +PERL_PATH = /usr/bin/perl +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = YES +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = NO +CLASS_GRAPH = YES +COLLABORATION_GRAPH = YES +UML_LOOK = NO +TEMPLATE_RELATIONS = NO +INCLUDE_GRAPH = YES +INCLUDED_BY_GRAPH = YES +CALL_GRAPH = NO +GRAPHICAL_HIERARCHY = YES +DOT_IMAGE_FORMAT = png +DOT_PATH = +DOTFILE_DIRS = +MAX_DOT_GRAPH_WIDTH = 1024 +MAX_DOT_GRAPH_HEIGHT = 1024 +MAX_DOT_GRAPH_DEPTH = 1000 +GENERATE_LEGEND = YES +DOT_CLEANUP = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- +SEARCHENGINE = NO diff --git a/kttsd/filters/xhtml2ssml/demonstration.html b/kttsd/filters/xhtml2ssml/demonstration.html new file mode 100644 index 0000000..89bf8a3 --- /dev/null +++ b/kttsd/filters/xhtml2ssml/demonstration.html @@ -0,0 +1,5 @@ + + +

Isn't it such a nice and bold day today?

+ + diff --git a/kttsd/filters/xhtml2ssml/main.cpp b/kttsd/filters/xhtml2ssml/main.cpp new file mode 100644 index 0000000..822d068 --- /dev/null +++ b/kttsd/filters/xhtml2ssml/main.cpp @@ -0,0 +1,22 @@ + +#include +#include +#include +#include +#include +#include "xhtml2ssml.h" +#include "xmlelement.h" + +int main(int argc, char *argv[]) { + QApplication a(argc, argv); + QFile f("demonstration.html"); + QXmlInputSource input(&f); + QXmlSimpleReader reader; + XHTMLToSSMLParser *parser = new XHTMLToSSMLParser(); + reader.setContentHandler(parser); + reader.parse(input); + std::cout << parser->convertedText() << "\n"; + delete parser; + return 0; +} + diff --git a/kttsd/filters/xhtml2ssml/tagmappingrc b/kttsd/filters/xhtml2ssml/tagmappingrc new file mode 100644 index 0000000..425af8e --- /dev/null +++ b/kttsd/filters/xhtml2ssml/tagmappingrc @@ -0,0 +1,5 @@ +# This is a comment +# and another one +# a html 'b' or 'strong' tag is mapped to 'emphasis level="strong"' +b:emphasis level="strong" +strong:emphasis level="strong" diff --git a/kttsd/filters/xhtml2ssml/xhtml2ssml.cpp b/kttsd/filters/xhtml2ssml/xhtml2ssml.cpp new file mode 100644 index 0000000..7c77b9e --- /dev/null +++ b/kttsd/filters/xhtml2ssml/xhtml2ssml.cpp @@ -0,0 +1,105 @@ + + +/**************************************************************************** + XHTMLToSSMLParser class + + Parses a piece of XHTML markup and converts into SSML. + ------------------- + Copyright: + (C) 2004 by Paul Giannaros + ------------------- + Original author: Paul Giannaros +******************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; version 2 of the License. * + * * + ***************************************************************************/ + +#include +#include +#include +#include +#include + +#include "xmlelement.h" +#include "xhtml2ssml.h" + + +/// Document parsing begin. Init stuff here. +bool XHTMLToSSMLParser::startDocument() { + /// Read the file which maps xhtml tags -> ssml tags. Look at the file for more information. + QFile file("tagmappingrc"); + if(!file.open(IO_ReadOnly)) { + std::cerr << "Could not read config file 'tagmappingrc'. Please check that it exists and is readable.\n"; + // Kill further parsing + return false; + } + QTextStream stream(&file); + // File parsing. + bool linestatus = true; + while(!stream.atEnd()) { + linestatus = readFileConfigEntry(stream.readLine()); + // If there's some syntactical error in the file then return false. + if(!linestatus) + return false; + /// Maybe call processEvents() to prevent GUI blockages? + } + return true; +} + +bool XHTMLToSSMLParser::startElement(const QString &, const QString &, const QString &qName, const QXmlAttributes &atts) { + QString attributes = ""; + if(atts.length() > 0) { + const int attsLength = atts.lenght(); + for(int i = 0; i < attsLength; ++i) + attributes += " " + atts.qName(i) + "=\"" + atts.value(i) + "\""; + } + QString fromelement = qName + attributes; + // If this element is one of the keys that was specified in the configuration file, get what it should be converted to and + // append to the output string. + QString toelement = m_xhtml2ssml[fromelement]; + if(toelement) + m_output.append(XMLElement::fromQString(toelement).startTag()); + return true; +} + +bool XHTMLToSSMLParser::endElement(const QString &, const QString &, const QString &qName) { + QString fromelement = qName; + QString toelement = m_xhtml2ssml[fromelement]; + if(toelement) + m_output.append(XMLElement::fromQString(toelement).endTag()); + return true; +} + +bool XHTMLToSSMLParser::characters(const QString &characters) { + m_output.append(characters); + return true; +} + + +QString XHTMLToSSMLParser::convertedText() { + return m_output.simplifyWhiteSpace(); +} + +/// Parse a line from the configuration file which maps xhtml : ssml equivalent. +/// It makes entries in the m_xhtml2ssml map accordingly. +/// @param line A line from a file to parse +/// @returns true if the syntax of the line was okay and the parsing succeeded - false otherwise. +bool XHTMLToSSMLParser::readFileConfigEntry(const QString &line) { + // comments + if(line.stripWhiteSpace().startsWith("#")) { + return true; + } + // break into QStringList + // the second parameter to split is the string, with all space simplified and all space around the : removed, i.e + // "something : somethingelse" -> "something:somethingelse" + QStringList keyvalue = QStringList::split(":", line.simplifyWhiteSpace().replace(" :", ":").replace(": ", ":")); + if(keyvalue.count() != 2) + return false; + m_xhtml2ssml[keyvalue[0]] = keyvalue[1]; + return true; +} diff --git a/kttsd/filters/xhtml2ssml/xhtml2ssml.h b/kttsd/filters/xhtml2ssml/xhtml2ssml.h new file mode 100644 index 0000000..7271dc0 --- /dev/null +++ b/kttsd/filters/xhtml2ssml/xhtml2ssml.h @@ -0,0 +1,61 @@ + +/**************************************************************************** + XHTMLToSSMLParser class + + Parses a piece of XHTML markup and converts into SSML. + ------------------- + Copyright: + (C) 2004 by Paul Giannaros + ------------------- + Original author: Paul Giannaros +******************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; version 2 of the License. * + * * + ***************************************************************************/ + + +#ifndef _XHTML2SSML_H_ +#define _XHTML2SSML_H_ + +#include +#include + +typedef QMap QStringMap; +class QString; + +class XHTMLToSSMLParser : public QXmlDefaultHandler { + +public: + /// No need to reimplement constructor.. + /// The document parsing starts + bool startDocument(); + /// start of an element encountered () + bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts); + /// end of an element encountered () + bool endElement(const QString &namespaceURI, const QString &localName, const QString &qName); + /// text encountered (blah bah blah) + bool characters(const QString &); + + /// Get the output text that was generated during the parsing. + /// @returns The converted text. + QString convertedText(); + + /// Parse a line from the configuration file which maps xhtml : ssml equivalent. + /// It makes entries in the m_xhtml2ssml map accordingly. + /// @param line A line from a file to parse + /// @returns true if the syntax of the line was okay and the parsing succeeded - false otherwise. + bool readFileConfigEntry(const QString &line); + +private: + /// Dict of xhtml tags -> ssml tags + QStringMap m_xhtml2ssml; + /// The output of the conversion + QString m_output; +}; + +#endif diff --git a/kttsd/filters/xhtml2ssml/xhtml2ssml.kdevelop b/kttsd/filters/xhtml2ssml/xhtml2ssml.kdevelop new file mode 100644 index 0000000..691735f --- /dev/null +++ b/kttsd/filters/xhtml2ssml/xhtml2ssml.kdevelop @@ -0,0 +1,112 @@ + + + + Paul Giannaros + ceruleanblaze@gmail.com + $VERSION$ + KDevTrollProject + C++ + + Qt + + + + + + + + + false + false + + + *.o,*.lo,CVS + false + + + + + bash + bash_bugs + clanlib + w3c-dom-level2-html + fortran_bugs_gcc + gnome1 + gnustep + gtk + gtk_bugs + haskell + haskell_bugs_ghc + java_bugs_gcc + java_bugs_sun + kde2book + opengl + pascal_bugs_fp + php + php_bugs + perl + perl_bugs + python + python_bugs + qt-kdev3 + ruby + ruby_bugs + sdl + stl + w3c-svg + sw + w3c-uaag10 + wxwidgets_bugs + + + KDE Libraries (Doxygen) + + + + + + + + + + + + + + + + + + + + executable + + + + + kdeincludedb + qtincludedb + qtincludesdb + kgmailtoincludedb + + + true + true + true + false + true + true + true + 250 + 400 + 250 + + + + true + true + true + true + -C + + diff --git a/kttsd/filters/xhtml2ssml/xhtml2ssml.kdevelop.pcs b/kttsd/filters/xhtml2ssml/xhtml2ssml.kdevelop.pcs new file mode 100644 index 0000000..4cdb884 Binary files /dev/null and b/kttsd/filters/xhtml2ssml/xhtml2ssml.kdevelop.pcs differ diff --git a/kttsd/filters/xhtml2ssml/xhtml2ssml.kdevses b/kttsd/filters/xhtml2ssml/xhtml2ssml.kdevses new file mode 100644 index 0000000..7128bc6 --- /dev/null +++ b/kttsd/filters/xhtml2ssml/xhtml2ssml.kdevses @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kttsd/filters/xhtml2ssml/xhtml2ssml.pro b/kttsd/filters/xhtml2ssml/xhtml2ssml.pro new file mode 100644 index 0000000..a9b5a4a --- /dev/null +++ b/kttsd/filters/xhtml2ssml/xhtml2ssml.pro @@ -0,0 +1,10 @@ +###################################################################### +# Automatically generated by qmake (1.07a) Tue Dec 21 21:18:47 2004 +###################################################################### + +TEMPLATE = app +INCLUDEPATH += . + +# Input +HEADERS += xhtml2ssml.h xmlelement.h +SOURCES += main.cpp xhtml2ssml.cpp xmlelement.cpp diff --git a/kttsd/filters/xhtml2ssml/xmlelement.cpp b/kttsd/filters/xhtml2ssml/xmlelement.cpp new file mode 100644 index 0000000..53fa4f6 --- /dev/null +++ b/kttsd/filters/xhtml2ssml/xmlelement.cpp @@ -0,0 +1,102 @@ +/**************************************************************************** + XMLElement class + + Representation of an XML element with methods for getting/setting + attributes and generating "opening" and "closing" tags. + ------------------- + Copyright: + (C) 2004 by Paul Giannaros + ------------------- + Original author: Paul Giannaros +******************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; version 2 of the License. * + * * + ***************************************************************************/ + +#include "xmlelement.h" +#include +#include + +/// Constructors +XMLElement::XMLElement() { + m_name = ""; + m_attrmapper = AttributeToValueMap(); +} +XMLElement::XMLElement(const QString &name) { + m_name = name; + m_attrmapper = AttributeToValueMap(); +} +/// Destructor +XMLElement::~XMLElement() { + return; +} + +/// Copy constructor +XMLElement::XMLElement(const XMLElement &element) { + m_attrmapper = element.m_attrmapper; + m_name = element.m_name; +} + +/// Assignement operator +XMLElement XMLElement::operator=(const XMLElement &element) { + m_attrmapper = element.m_attrmapper; + m_name = element.m_name; + return *this; +} + +QString XMLElement::name() { + return m_name; +} +QString XMLElement::startTag() { + QString output = "<" + m_name + " "; + for(AttributeToValueMap::Iterator it = m_attrmapper.begin(); it != m_attrmapper.end(); ++it) { + output.append(it.key() + "=\"" + it.data() + "\" "); + } + output = output.left(output.length() - 1); + // Get rid of the space at the end and then append a '>' + output.append(">"); + return output; +} + +QString XMLElement::endTag() { + return ""; +} + +void XMLElement::setAttribute(const QString &attr, const QString &value) { + m_attrmapper[attr] = value; +} +QString XMLElement::attribute(const QString &attr) { + return m_attrmapper[attr]; +} + +QString XMLElement::toQString() { + QString tag = startTag(); + return tag.left(tag.length() - 1).right(tag.length() - 2); +} + +XMLElement XMLElement::fromQString(const QString &str) { + QStringList sections = QStringList::split(" ", str); + QString tagname = sections[0]; + XMLElement e(tagname.latin1()); + + sections.pop_front(); + // Loop over the remaining strings which are attributes="values" + if(sections.count()) { + const int sectionsCount = sections.count(); + for(int i = 0; i < sectionsCount; ++i) { + QStringList list = QStringList::split("=", sections[i]); + if(list.count() != 2) { + std::cerr << "XMLElement::fromQString: Cannot convert list: " << list.join("|") << ". `" << str << "' is not in valid format.\n"; + return XMLElement(" "); + } + e.setAttribute(list[0], list[1].left(list[1].length() - 1).right(list[1].length() -2)); + } + } + return e; +} + diff --git a/kttsd/filters/xhtml2ssml/xmlelement.h b/kttsd/filters/xhtml2ssml/xmlelement.h new file mode 100644 index 0000000..c78cd6f --- /dev/null +++ b/kttsd/filters/xhtml2ssml/xmlelement.h @@ -0,0 +1,91 @@ +/**************************************************************************** + XMLElement class + + Representation of an XML element with methods for getting/setting + attributes and generating "opening" and "closing" tags. + ------------------- + Copyright: + (C) 2004 by Paul Giannaros + ------------------- + Original author: Paul Giannaros +******************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; version 2 of the License. * + * * + ***************************************************************************/ + + +#ifndef XMLELEMENT_H +#define XMLELEMENT_H + +#include + +class QString; + +typedef QMap AttributeToValueMap; + +class XMLElement { +public: + XMLElement(); + XMLElement(const QString &name); + ~XMLElement(); + + /// Copy constructor + XMLElement(const XMLElement &); + + /// Assignment operator + XMLElement operator=(const XMLElement &element); + + /// Get the name of the tag (the text between the greater than and less than symbols). + /// @returns the name of the tag. + QString name(); + + /// set the name of the tag. + /// @param name the new name of the tag. + void setName(const QString &name); + + /// Get a textual representation of the starting of the tag with all attributes and their values set out. + /// @verbatim + /// XMLElement element("elem"); + /// element.addAttribute("foo", "bar"); + /// element.startTag(); <- + /// @endverbatim + /// @returns A textual representation of the start of the element. + QString startTag(); + + /// Get a textual representation of the closed tag that XMLElement represents. + /// @returns A textual representation of the closed tag represented by the XMLElement. + QString endTag(); + + /// Create an attribute and set its value. + /// @param attr The attribute. + /// @param value The value of the attribute. + void setAttribute(const QString &attr, const QString &value); + + /// Get the value of an attribute. + /// @param attr The attribute. + /// @returns The value of @param attr + QString attribute(const QString &attr); + + /// Convert to a QString. + /// Had issues with QMap and custom classes. For now you can just convert to/from QString and use + /// That as the key/value pair. + /// @returns A QString representation of the XMLAttribute. + QString toQString(); + + /// Create an XMLElement from a QString. + /// @param str The QString to convert from. Must be of the following syntax- "foo name=\"bar\"" + static XMLElement fromQString(const QString &str); + +private: + /// The name of the tag. + QString m_name; + /// Attribute : value mappings. + AttributeToValueMap m_attrmapper; +}; + +#endif -- cgit v1.2.1