// // C++ Implementation: docbookgenerator // // Description: // // // Author: Robert Vogl , (C) 2005 // // Copyright: See COPYING file that comes with this distribution // // // Qt includes #include #include //KDE includes #include #include #include // App specific includes #include "docbookgenerator.h" DocbookGenerator::DocbookGenerator() { } DocbookGenerator::~DocbookGenerator() { } void DocbookGenerator::writeBook(TQTextStream &doc, ListViewInterface *item) { kdDebug(100200) << "DocTreeViewImpl::writeBook()" << endl; // read item's content TQString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( whoAmI != "RobDocument" ) return; // add node to document doc << "" << endl; // process childs ListViewInterface *i = static_cast(item->firstChild()); TQString itemType; while( i ){ itemType = (i->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( itemType == "BookInfo" ){ writeBookInfo( doc, i ); } else if ( itemType == "Chapter" ) { writeChapter( doc, i ); } // next child i = static_cast(i->nextSibling()); } doc << "" << endl; } void DocbookGenerator::writeBookInfo(TQTextStream &doc, ListViewInterface *item) { kdDebug(100200) << "DocTreeViewImpl::writeBookInfo()" << endl; // read item's content TQString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( whoAmI != "BookInfo" ) return; // add node to document doc << "" << endl; writeTitleOfBook( doc, item ); // process childs ListViewInterface *i = static_cast(item->firstChild()); TQString itemType; while( i ){ itemType = (i->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( itemType == "KeywordSet" ){ writeKeywordSet( doc, i ); } else if ( itemType == "Abstract" ) { writeAbstract( doc, i ); } else if ( itemType == "AuthorGroup" ) { writeAuthorGroup( doc, i ); } else if ( itemType == "Date" ) { writeDate( doc, i ); } else if ( itemType == "ReleaseInfo" ) { writeReleaseInfo( doc, i ); } // next child i = static_cast(i->nextSibling()); } doc << "" << endl; } void DocbookGenerator::writeTitleOfBook(TQTextStream &doc, ListViewInterface *item) { kdDebug(100200) << "DocTreeViewImpl::writeTitle()" << endl; // read item's content TQString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( whoAmI != "BookInfo" ) return; // Documents title is stored in root element (parent of BookInfo) ListViewInterface *parent = static_cast(item->parent()); if ( parent ){ TQString title = parent->text(0); // add node to document doc << "" << title << "" << endl; } } void DocbookGenerator::writeAuthorGroup(TQTextStream &doc, ListViewInterface *item) { kdDebug(100200) << "DocTreeViewImpl::writeAuthorGroup()" << endl; // read item's content TQString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( whoAmI != "AuthorGroup" ) return; // add node to document doc << "" << endl; // process childs ListViewInterface *i = static_cast(item->firstChild()); TQString itemType; while( i ){ itemType = (i->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( itemType == "Author" ){ writeAuthor( doc, i ); } // next child i = static_cast(i->nextSibling()); } doc << "" << endl; } void DocbookGenerator::writeAuthor(TQTextStream &doc, ListViewInterface *item) { kdDebug(100200) << "DocTreeViewImpl::writeAuthor()" << endl; // read item's content TQString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( whoAmI != "Author" ) return; TQString author = TQString::null; author = ( item->getValue(KSayItGlobal::RAWDATA) ).toString(); // add node to document doc << "" << endl; // process childs doc << "" << author.section(' ', 0, 0) << "" << endl; doc << "" << author.section(' ', 1, 1) << "" << endl; doc << "" << endl; } void DocbookGenerator::writeDate(TQTextStream &doc, ListViewInterface *item) { kdDebug(100200) << "DocTreeViewImpl::writeDate()" << endl; // read item's content TQString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( whoAmI != "Date" ) return; TQString date = item->text(1); // add node to document doc << "" << date << "" << endl; } void DocbookGenerator::writeReleaseInfo(TQTextStream &doc, ListViewInterface *item) { kdDebug(100200) << "DocTreeViewImpl::writeReleaseInfo()" << endl; // read item's content TQString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( whoAmI != "ReleaseInfo" ) return; TQString releaseinfo = item->text(1); // add node to document doc << "" << releaseinfo << "" << endl; } void DocbookGenerator::writeKeywordSet(TQTextStream &doc, ListViewInterface *item) { kdDebug(100200) << "DocTreeViewImpl::writeKeywordSet()" << endl; // read item's content TQString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( whoAmI != "KeywordSet" ) return; // add node to document doc << "" << endl; // process childs ListViewInterface *i = static_cast(item->firstChild()); TQString itemType; while( i ){ itemType = ( i->getValue(KSayItGlobal::XMLCONTEXTNAME) ).toString(); if ( itemType == "Keyword" ){ writeKeyword( doc, i ); } // next child i = static_cast(i->nextSibling()); } doc << "" << endl; } void DocbookGenerator::writeKeyword(TQTextStream &doc, ListViewInterface *item) { kdDebug(100200) << "DocTreeViewImpl::writeKeyword()" << endl; // read item's content TQString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( whoAmI != "Keyword" ) return; // TQString keyword = item->text( 0 ); TQString keyword = TQString::null; keyword = (item->getValue(3)).toString(); // add node to document doc << "" << keyword << "" << endl; // process childs // no childs } void DocbookGenerator::writeAbstract(TQTextStream &doc, ListViewInterface *item) { kdDebug(100200) << "DocTreeViewImpl::writeAbstract()" << endl; // read item's content TQString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( whoAmI != "Abstract" ) return; // add node to document doc << "" << endl; // process childs ListViewInterface *i = static_cast(item->firstChild()); TQString itemType; while( i ){ itemType = (i->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( itemType == "Para" ){ writePara( doc, i ); } // next child i = static_cast(i->nextSibling()); } doc << "" << endl; } void DocbookGenerator::writeChapter( TQTextStream &doc, ListViewInterface *item) { kdDebug(100200) << "DocTreeViewImpl::writeChapter()" << endl; // read item's content TQString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( whoAmI != "Chapter" ) return; TQString title = item->text(0); // add node to document doc << "" << endl; doc << "" << title << "" << endl; // process childs ListViewInterface *i = static_cast(item->firstChild()); TQString itemType; while( i ){ itemType = (i->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( itemType == "Para" ){ writePara( doc, i ); } else if ( itemType == "Sect1" ) { writeSect1( doc, i ); } // next child i = static_cast(i->nextSibling()); } doc << "" << endl; } void DocbookGenerator::writeSect1(TQTextStream &doc, ListViewInterface *item) { kdDebug(100200) << "DocTreeViewImpl::writeSect1()" << endl; // read item's content TQString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( whoAmI != "Sect1" ) return; TQString title = item->text(0); // add node to document doc << "" << endl; doc << "" << title << "" << endl; // process childs ListViewInterface *i = static_cast(item->firstChild()); TQString itemType; while( i ){ itemType = (i->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( itemType == "Para" ){ writePara( doc, i ); } else if ( itemType == "Sect2" ) { writeSect2( doc, i ); } // next child i = static_cast(i->nextSibling()); } doc << "" << endl; } void DocbookGenerator::writeSect2(TQTextStream &doc, ListViewInterface *item) { kdDebug(100200) << "DocTreeViewImpl::writeSect1()" << endl; // read item's content TQString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( whoAmI != "Sect2" ) return; TQString title = item->text(0); // add node to document doc << "" << endl; doc << "" << title << "" << endl; // process childs ListViewInterface *i = static_cast(item->firstChild()); TQString itemType; while( i ){ itemType = ( i->getValue(KSayItGlobal::XMLCONTEXTNAME) ).toString(); if ( itemType == "Para" ){ writePara( doc, i ); } else if ( itemType == "Sect3" ) { writeSect3( doc, i ); } // next child i = static_cast(i->nextSibling()); } doc << "" << endl; } void DocbookGenerator::writeSect3(TQTextStream &doc, ListViewInterface *item) { kdDebug(100200) << "DocTreeViewImpl::writeSect3()" << endl; // read item's content TQString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( whoAmI != "Sect3" ) return; TQString title = item->text(0); // add node to document doc << "" << endl; doc << "" << title << "" << endl; // process childs ListViewInterface *i = static_cast(item->firstChild()); TQString itemType; while( i ){ itemType = (i->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( itemType == "Para" ){ writePara( doc, i ); } else if ( itemType == "Sect4" ) { writeSect4( doc, i ); } // next child i = static_cast(i->nextSibling()); } doc << "" << endl; } void DocbookGenerator::writeSect4(TQTextStream &doc, ListViewInterface *item) { kdDebug(100200) << "DocTreeViewImpl::writeSect4()" << endl; // read item's content TQString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( whoAmI != "Sect4" ) return; TQString title = item->text(0); // add node to document doc << "" << endl; doc << "" << title << "" << endl; // process childs ListViewInterface *i = static_cast(item->firstChild()); TQString itemType; while( i ){ itemType = (i->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( itemType == "Para" ){ writePara( doc, i ); } else if ( itemType == "Sect5" ) { writeSect5( doc, i ); } // next child i = static_cast(i->nextSibling()); } doc << "" << endl; } void DocbookGenerator::writeSect5(TQTextStream &doc, ListViewInterface *item) { kdDebug(100200) << "DocTreeViewImpl::writeSect5()" << endl; // read item's content TQString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( whoAmI != "Sect5" ) return; TQString title = item->text(0); // add node to document doc << "" << endl; doc << "" << title << "" << endl; // process childs ListViewInterface *i = static_cast(item->firstChild()); TQString itemType; while( i ){ itemType = (i->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( itemType == "Para" ){ writePara( doc, i ); } // next child i = static_cast(i->nextSibling()); } doc << "" << endl; } void DocbookGenerator::writePara(TQTextStream &doc, ListViewInterface *item) { kdDebug(100200) << "DocTreeViewImpl::writePara()" << endl; // read item's content TQString whoAmI = (item->getValue(KSayItGlobal::XMLCONTEXTNAME)).toString(); if ( whoAmI != "Para" ) return; TQString data = ( item->getValue(KSayItGlobal::RAWDATA) ).toString(); // add node to document doc << "" << endl; doc << data << endl; doc << "" << endl; // process childs // childs are embedded in data. }