Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

bibtexfactory.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   bibtexfactory.cpp                                                             *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   Read the file COPYING for details.                                    *
00011  *                                                                         *
00012  *   copyright: (C) 2003 by Jan Mueller                                    *
00013  *   email: janmueller7@hotmail.com                                        *
00014  *                                                                         *
00015  ***************************************************************************/
00016 
00017 #include "bibtexfactory.h"
00018 #include <qstring.h>
00019 #include <qsqlquery.h>
00020 #include <qsqlcursor.h>
00021 #include <qregexp.h>
00022 #include "bibtextypes.h"
00023 
00024 
00025 BibTexFactory::BibTexFactory(QSqlCursor &cur) {
00026 }
00027 
00028 PublBibTexFactory::PublBibTexFactory(QSqlCursor &cur): BibTexFactory(cur) {
00029   
00030   int bibtextype=cur.value("entrytype").toInt();
00031   QString publisher_no=cur.value("publisher_no").toString();
00032   QString publisher, address;
00033   QSqlQuery query("select publisher.name, publisher.city from publisher where no="+publisher_no);
00034   if(query.first()) {
00035     publisher=query.value(0).toString();
00036     address=query.value(1).toString();
00037   }
00038 
00039   QString journal_no=cur.value("journal_no").toString();
00040   QString journal;
00041   query.exec("select journal.name from journal where no="+journal_no);
00042   if(query.first()) 
00043     journal=query.value(0).toString();
00044 
00045   QString no=cur.value("no").toString();
00046   QString editor=cur.value("editor").toString();
00047   QString title=cur.value("title").toString();
00048   QString year=cur.value("year").toString();
00049   QString volume=cur.value("volume").toString();
00050   QString number=cur.value("number").toString();
00051   QString series=cur.value("series").toString();
00052   QString edition=cur.value("edition").toString();
00053   QString month=cur.value("month").toString();
00054   QString pages=cur.value("pages").toString();
00055   QString ptype=cur.value("type").toString();
00056   QString key=cur.value("key").toString();
00057   QString organization=cur.value("organization").toString();
00058   QString howpublished=cur.value("howpublished").toString();  
00059 
00060 
00061   query.exec("select author.firstname, author.lastname from author, publication_author where author.no=publication_author.author_no and publication_author.publication_no="+no+" order by publication_author.author_order");
00062 
00063   QString idname, firstname, lastname, author;
00064   if(query.first()) {
00065     idname=query.value(1).toString();
00066     do {
00067       firstname=query.value(0).toString();
00068       lastname=query.value(1).toString();
00069       author+=lastname+", "+firstname+" and ";
00070     } while(query.next());
00071     author=author.left(author.length()-5);
00072   } 
00073   else
00074     author="NoName"+no;
00075 
00076 
00077   QString label=idname+year;
00078   query.exec("select publication.no as no, publication.created as created from publication, publication_author, author where publication.year='"+year+"' and publication.no = publication_author.publication_no and publication_author.author_no=author.no and author.lastname='"+idname+"' union select part.no as no, part.created as created from part, part_author, author, publication where part.no = part_author.part_no and part_author.author_no=author.no and author.lastname='"+idname+"' and part.publication_no=publication.no and publication.year='"+year+"' order by created");
00079   int bibindex=-1;
00080   while(query.next() && query.value(0).toInt()!=cur.value("no").toInt())
00081     bibindex++;
00082 
00083   if(bibindex>0)
00084     label+=char('a'+bibindex);
00085     
00086   switch(bibtextype) {
00087   case BT_BOOK:
00088     start(label, "@BOOK");
00089     if(!author.isEmpty()) addAuthor(author);
00090     if(!editor.isEmpty()) addEditor(editor);
00091     if(!title.isEmpty()) addTitle(title);
00092     if(!publisher.isEmpty()) addPublisher(publisher);
00093     if(!year.isEmpty()) addYear(year);
00094     if(!volume.isEmpty()) addVolume(volume);
00095     if(!number.isEmpty()) addNumber(number);
00096     if(!series.isEmpty()) addSeries(series);
00097     if(!address.isEmpty()) addAddress(address);
00098     if(!edition.isEmpty()) addEdition(edition);
00099     if(!month.isEmpty()) addMonth(month);
00100     end();
00101     break;
00102   case BT_INBOOK:     // crossref-type
00103     start("Ref"+no, "@INBOOK");
00104     if(!author.isEmpty()) addAuthor(author);
00105     if(!title.isEmpty()) addTitle(title);
00106     if(!publisher.isEmpty()) addPublisher(publisher);
00107     if(!year.isEmpty()) addYear(year);
00108     if(!volume.isEmpty()) addVolume(volume);
00109     if(!number.isEmpty()) addNumber(number);
00110     if(!series.isEmpty()) addSeries(series);
00111     if(!ptype.isEmpty()) addType(ptype);
00112     if(!address.isEmpty()) addAddress(address);
00113     if(!edition.isEmpty()) addEdition(edition);
00114     if(!month.isEmpty()) addMonth(month);
00115     if(!key.isEmpty()) addKey(key);
00116     end();
00117     break;
00118   case BT_INCOLLECTION:     // crossref-type
00119     start("Ref"+no, "@INCOLLECTION");
00120     if(!title.isEmpty()) addBooktitle(title);
00121     if(!publisher.isEmpty()) addPublisher(publisher);
00122     if(!year.isEmpty()) addYear(year);
00123     if(!author.isEmpty()) addEditor(author);
00124     if(!volume.isEmpty()) addVolume(volume);
00125     if(!number.isEmpty()) addNumber(number);
00126     if(!series.isEmpty()) addSeries(series);
00127     if(!ptype.isEmpty()) addType(ptype);
00128     if(!address.isEmpty()) addAddress(address);
00129     if(!edition.isEmpty()) addEdition(edition);
00130     if(!month.isEmpty()) addMonth(month);
00131     if(!key.isEmpty()) addKey(key);
00132     end();
00133     break;
00134   case BT_BOOKLET:
00135     start(label, "@BOOKLET");
00136     if(!title.isEmpty()) addTitle(title);
00137     if(!author.isEmpty()) addAuthor(author);
00138     if(!howpublished.isEmpty()) addHowpublished(howpublished);
00139     if(!address.isEmpty()) addAddress(address);
00140     if(!month.isEmpty()) addMonth(month);
00141     if(!year.isEmpty()) addYear(year);
00142     end();
00143     break;
00144   case BT_MISC:
00145     start(label, "@MISC");
00146     if(!author.isEmpty()) addAuthor(author);
00147     if(!title.isEmpty()) addTitle(title);
00148     if(!howpublished.isEmpty()) addHowpublished(howpublished);
00149     if(!month.isEmpty()) addMonth(month);
00150     if(!year.isEmpty()) addYear(year);
00151     end();
00152     break;
00153   case BT_ARTICLE:
00154     start(label, "@ARTICLE");
00155     if(!title.isEmpty()) addTitle(title);
00156     if(!author.isEmpty()) addAuthor(author);
00157     if(!journal.isEmpty()) addJournal(journal);
00158     if(!year.isEmpty()) addYear(year);
00159     if(!volume.isEmpty()) addVolume(volume);
00160     if(!number.isEmpty()) addNumber(number);
00161     if(!pages.isEmpty()) addPages(pages);
00162     if(!month.isEmpty()) addMonth(month);
00163     if(!key.isEmpty()) addKey(key);
00164     end();
00165     break;
00166   case BT_MANUAL:
00167     start(label, "@MANUAL");
00168     if(!title.isEmpty()) addTitle(title);
00169     if(!author.isEmpty()) addAuthor(author);
00170     if(!organization.isEmpty()) addOrganization(organization);
00171     if(!address.isEmpty()) addAddress(address);
00172     if(!edition.isEmpty()) addEdition(edition);
00173     if(!month.isEmpty()) addMonth(month);
00174     if(!year.isEmpty()) addYear(year);
00175     end();
00176     break;
00177   case BT_PROCEEDING:
00178     start(label, "@PROCEEDINGS");
00179     if(!title.isEmpty()) addTitle(title);
00180     if(!year.isEmpty()) addYear(year);
00181     if(!editor.isEmpty()) addEditor(editor);
00182     if(!volume.isEmpty()) addVolume(volume);
00183     if(!number.isEmpty()) addNumber(number);
00184     if(!series.isEmpty()) addSeries(series);
00185     if(!address.isEmpty()) addAddress(address);
00186     if(!month.isEmpty()) addMonth(month);
00187     if(!organization.isEmpty()) addOrganization(organization);
00188     if(!publisher.isEmpty()) addPublisher(publisher);
00189     end();
00190     break;
00191   case BT_INPROCEEDING:     // crossref-type
00192     start("Ref"+no, "@INPROCEEDINGS");
00193     if(!title.isEmpty()) addBooktitle(title);
00194     if(!year.isEmpty()) addYear(year);
00195     if(!author.isEmpty()) addEditor(author);
00196     if(!volume.isEmpty()) addVolume(volume);
00197     if(!number.isEmpty()) addNumber(number);
00198     if(!series.isEmpty()) addSeries(series);
00199     if(!address.isEmpty()) addAddress(address);
00200     if(!month.isEmpty()) addMonth(month);
00201     if(!organization.isEmpty()) addOrganization(organization);
00202     if(!publisher.isEmpty()) addPublisher(publisher);
00203     if(!key.isEmpty()) addKey(key);
00204     end();
00205     break;
00206   case BT_TECHREPORT:
00207     start(label, "@TECHREPORT");
00208     if(!author.isEmpty()) addAuthor(author);
00209     if(!title.isEmpty()) addTitle(title);
00210     if(!organization.isEmpty()) addInstitution(organization);
00211     if(!year.isEmpty()) addYear(year);
00212     if(!address.isEmpty()) addAddress(address);
00213     if(!ptype.isEmpty()) addType(ptype);
00214     if(!number.isEmpty()) addNumber(number);
00215     if(!month.isEmpty()) addMonth(month);
00216     end();
00217     break;
00218   case BT_UNPUBLISHED:
00219     start(label, "@UNPUBLISHED");
00220     if(!author.isEmpty()) addAuthor(author);
00221     if(!title.isEmpty()) addTitle(title);
00222     if(!month.isEmpty()) addMonth(month);
00223     if(!year.isEmpty()) addYear(year);
00224     end();
00225     break;
00226   case BT_PHDTHESIS:
00227     start(label, "@PHDTHESIS");
00228     if(!author.isEmpty()) addAuthor(author);
00229     if(!title.isEmpty()) addTitle(title);
00230     if(!organization.isEmpty()) addSchool(organization);
00231     if(!year.isEmpty()) addYear(year);
00232     if(!ptype.isEmpty()) addType(ptype);
00233     if(!address.isEmpty()) addAddress(address);
00234     if(!month.isEmpty()) addMonth(month);
00235     end();
00236     break;
00237   case BT_MASTERTHESIS:
00238     start(label, "@MASTERSTHESIS");
00239     if(!author.isEmpty()) addAuthor(author);
00240     if(!title.isEmpty()) addTitle(title);
00241     if(!organization.isEmpty()) addSchool(organization);
00242     if(!year.isEmpty()) addYear(year);
00243     if(!ptype.isEmpty()) addType(ptype);
00244     if(!address.isEmpty()) addAddress(address);
00245     if(!month.isEmpty()) addMonth(month);
00246     end();
00247     break;
00248     
00249   }
00250 }
00251 
00252 
00253 PartBibTexFactory::PartBibTexFactory(QSqlCursor &cur): BibTexFactory(cur) {
00254 
00255   QString no=cur.value("no").toString();
00256   int entrytype;
00257   QString year;
00258   QString publno;
00259   QSqlQuery query("select publication.entrytype, publication.year, publication.no from publication, part where publication.no=part.publication_no and part.no="+no);
00260   if(query.first()) {
00261     entrytype=query.value(0).toInt();
00262     year=query.value(1).toString();
00263     publno=query.value(2).toString();
00264   }
00265 
00266 
00267   QString title=cur.value("title").toString();
00268   QString key=cur.value("key").toString();
00269   QString pages=cur.value("pages").toString();
00270   QString chapter=cur.value("partno").toString();  
00271   QString crossref="Ref"+publno;
00272 
00273   
00274   query.exec("select author.firstname, author.lastname from author, part_author where author.no=part_author.author_no and part_author.part_no="+no+" order by part_author.author_order");
00275 
00276   QString idname, firstname, lastname, author;
00277   if(query.first()) {
00278     idname=query.value(1).toString();
00279     do {
00280       firstname=query.value(0).toString();
00281       lastname=query.value(1).toString();
00282       author+=lastname+", "+firstname+" and ";
00283     } while(query.next());
00284     author=author.left(author.length()-5);
00285   } 
00286   else
00287     author="NoName"+cur.value("no").toString();
00288 
00289 
00290   QString label=idname+year;
00291   query.exec("select publication.no as no, publication.created as created from publication, publication_author, author where publication.year='"+year+"' and publication.no = publication_author.publication_no and publication_author.author_no=author.no and author.lastname='"+idname+"' union select part.no as no, part.created as created from part, part_author, author, publication where part.no = part_author.part_no and part_author.author_no=author.no and author.lastname='"+idname+"' and part.publication_no=publication.no and publication.year='"+year+"' order by created");
00292   int bibindex=-1;
00293   while(query.next() && query.value(0).toInt()!=cur.value("no").toInt())
00294     bibindex++;
00295 
00296   if(bibindex>0)
00297     label+=char('a'+bibindex);
00298     
00299   switch(entrytype) {
00300   case BT_INBOOK:
00301     start(label, "@INBOOK");
00302     if(!author.isEmpty()) addAuthor(author);
00303     if(!title.isEmpty()) addTitle(title);
00304     if(!chapter.isEmpty()) addChapter(chapter);
00305     if(!pages.isEmpty()) addPages(pages);
00306     if(!key.isEmpty()) addKey(key);
00307     if(!crossref.isEmpty()) addCrossRef(crossref);
00308     end();
00309     break;
00310   case BT_INCOLLECTION:
00311     start(label, "@INCOLLECTION");
00312     if(!author.isEmpty()) addAuthor(author);
00313     if(!title.isEmpty()) addTitle(title);
00314     if(!chapter.isEmpty()) addChapter(chapter);
00315     if(!pages.isEmpty()) addPages(pages);
00316     if(!key.isEmpty()) addKey(key);
00317     if(!crossref.isEmpty()) addCrossRef(crossref);
00318     end();
00319     break;
00320   case BT_INPROCEEDING:
00321     start(label, "@INPROCEEDINGS");
00322     if(!author.isEmpty()) addAuthor(author);
00323     if(!title.isEmpty()) addTitle(title);
00324     if(!pages.isEmpty()) addPages(pages);
00325     if(!key.isEmpty()) addKey(key);
00326     if(!crossref.isEmpty()) addCrossRef(crossref);
00327     end();
00328     break;
00329   }
00330 }
00331 
00332 QString BibTexFactory::getEntry() {
00333   return entry;
00334 }
00335 
00336 QString BibTexFactory::ascii2latex(QString &t) {
00337   QString s(t);
00338   s.replace(QRegExp(QString().fromLatin1("Ä")),"{\\\"A}");
00339   s.replace(QRegExp(QString().fromLatin1("Ë")),"{\\\"E}");
00340   s.replace(QRegExp(QString().fromLatin1("Ï")),"{\\\"I}");
00341   s.replace(QRegExp(QString().fromLatin1("Ö")),"{\\\"O}");
00342   s.replace(QRegExp(QString().fromLatin1("Ü")),"{\\\"U}");
00343   s.replace(QRegExp(QString().fromLatin1("ä")),"{\\\"a}");
00344   s.replace(QRegExp(QString().fromLatin1("ë")),"{\\\"e}");
00345   s.replace(QRegExp(QString().fromLatin1("ï")),"{\\\"i}");
00346   s.replace(QRegExp(QString().fromLatin1("ö")),"{\\\"o}");
00347   s.replace(QRegExp(QString().fromLatin1("ü")),"{\\\"u}");
00348   s.replace(QRegExp(QString().fromLatin1("ÿ")),"{\\\"y}");
00349   s.replace(QRegExp(QString().fromLatin1("Æ")),"{\\AE}");
00350   s.replace(QRegExp(QString().fromLatin1("æ")),"{\\ae}");
00351   s.replace(QRegExp(QString().fromLatin1("ß")),"{\\ss}");
00352   s.replace(QRegExp(QString().fromLatin1("Á")),"\\'{A}");
00353   s.replace(QRegExp(QString().fromLatin1("É")),"\\'{E}");
00354   s.replace(QRegExp(QString().fromLatin1("Í")),"\\'{I}");
00355   s.replace(QRegExp(QString().fromLatin1("Ó")),"\\'{O}");
00356   s.replace(QRegExp(QString().fromLatin1("Ú")),"\\'{U}");
00357   s.replace(QRegExp(QString().fromLatin1("Ý")),"\\'{Y}");
00358   s.replace(QRegExp(QString().fromLatin1("á")),"\\'{a}");
00359   s.replace(QRegExp(QString().fromLatin1("é")),"\\'{e}");
00360   s.replace(QRegExp(QString().fromLatin1("í")),"\\'{i}");
00361   s.replace(QRegExp(QString().fromLatin1("ó")),"\\'{o}");
00362   s.replace(QRegExp(QString().fromLatin1("ú")),"\\'{u}");
00363   s.replace(QRegExp(QString().fromLatin1("ý")),"\\'{y}");
00364   s.replace(QRegExp(QString().fromLatin1("À")),"\\`{A}");
00365   s.replace(QRegExp(QString().fromLatin1("È")),"\\`{E}");
00366   s.replace(QRegExp(QString().fromLatin1("Ì")),"\\`{I}");
00367   s.replace(QRegExp(QString().fromLatin1("Ò")),"\\`{O}");
00368   s.replace(QRegExp(QString().fromLatin1("Ù")),"\\`{U}");
00369   s.replace(QRegExp(QString().fromLatin1("à")),"\\`{a}");
00370   s.replace(QRegExp(QString().fromLatin1("è")),"\\`{e}");
00371   s.replace(QRegExp(QString().fromLatin1("ì")),"\\`{i}");
00372   s.replace(QRegExp(QString().fromLatin1("ò")),"\\`{o}");
00373   s.replace(QRegExp(QString().fromLatin1("ù")),"\\`{u}");
00374   s.replace(QRegExp(QString().fromLatin1("Â")),"\\^{A}");
00375   s.replace(QRegExp(QString().fromLatin1("Ê")),"\\^{E}");
00376   s.replace(QRegExp(QString().fromLatin1("Î")),"\\^{I}");
00377   s.replace(QRegExp(QString().fromLatin1("Ô")),"\\^{O}");
00378   s.replace(QRegExp(QString().fromLatin1("Û")),"\\^{U}");
00379   s.replace(QRegExp(QString().fromLatin1("â")),"\\^{a}");
00380   s.replace(QRegExp(QString().fromLatin1("ê")),"\\^{e}");
00381   s.replace(QRegExp(QString().fromLatin1("î")),"\\^{i}");
00382   s.replace(QRegExp(QString().fromLatin1("ô")),"\\^{o}");
00383   s.replace(QRegExp(QString().fromLatin1("û")),"\\^{u}");
00384   s.replace(QRegExp(QString().fromLatin1("Ã")),"\\~{A}");
00385   s.replace(QRegExp(QString().fromLatin1("Ñ")),"\\~{N}");
00386   s.replace(QRegExp(QString().fromLatin1("Õ")),"\\~{O}");
00387   s.replace(QRegExp(QString().fromLatin1("ã")),"\\~{a}");
00388   s.replace(QRegExp(QString().fromLatin1("ñ")),"\\~{n}");
00389   s.replace(QRegExp(QString().fromLatin1("õ")),"\\~{o}");
00390   s.replace(QRegExp(QString().fromLatin1("Å")),"\\r{A}");
00391   s.replace(QRegExp(QString().fromLatin1("å")),"\\r{a}");
00392   s.replace(QRegExp(QString().fromLatin1("Ç")),"\\c{C}");
00393   s.replace(QRegExp(QString().fromLatin1("ç")),"\\c{c}");
00394   s.replace(QRegExp(QString().fromLatin1("Ø")),"\\O");
00395   s.replace(QRegExp(QString().fromLatin1("ø")),"\\o");
00396   return s;
00397 }
00398 
00399 void BibTexFactory::start(QString label, QString ptype) {  entry=ptype+"{"+label;  }
00400 void BibTexFactory::end() { entry +="\n}"; }
00401 void BibTexFactory::addAddress(QString &s) { entry+=",\naddress=\""+ascii2latex(s)+"\""; }
00402 void BibTexFactory::addAuthor(QString &s) { entry+=",\nauthor=\""+ascii2latex(s)+"\""; }
00403 void BibTexFactory::addBooktitle(QString &s) { entry+=",\nbooktitle=\""+ascii2latex(s)+"\""; }
00404 void BibTexFactory::addChapter(QString &s) { entry+=",\nchapter=\""+ascii2latex(s)+"\""; }
00405 void BibTexFactory::addEdition(QString &s) { entry+=",\nedition=\""+ascii2latex(s)+"\""; }
00406 void BibTexFactory::addEditor(QString &s) { entry+=",\neditor=\""+ascii2latex(s)+"\""; }
00407 void BibTexFactory::addHowpublished(QString &s) { entry+=",\nhowpublished=\""+ascii2latex(s)+"\""; }
00408 void BibTexFactory::addInstitution(QString &s) { entry+=",\ninstitution=\""+ascii2latex(s)+"\""; }
00409 void BibTexFactory::addJournal(QString &s) { entry+=",\njournal=\""+ascii2latex(s)+"\""; }
00410 void BibTexFactory::addMonth(QString &s) { entry+=",\nmonth=\""+ascii2latex(s)+"\""; }
00411 void BibTexFactory::addNote(QString &s) { entry+=",\nnote=\""+ascii2latex(s)+"\""; }
00412 void BibTexFactory::addNumber(QString &s) { entry+=",\nnumber="+s; }
00413 void BibTexFactory::addOrganization(QString &s){ entry+=",\norganization=\""+ascii2latex(s)+"\""; }
00414 void BibTexFactory::addPages(QString &s) { entry+=",\npages=\""+ascii2latex(s)+"\""; }
00415 void BibTexFactory::addPublisher(QString &s) { entry+=",\npublisher=\""+ascii2latex(s)+"\""; }
00416 void BibTexFactory::addSchool(QString &s) { entry+=",\nschool=\""+ascii2latex(s)+"\""; }
00417 void BibTexFactory::addSeries(QString &s) { entry+=",\nseries=\""+ascii2latex(s)+"\""; }
00418 void BibTexFactory::addTitle(QString &s) { entry+=",\ntitle=\""+ascii2latex(s)+"\""; }
00419 void BibTexFactory::addType(QString &s) { entry+=",\ntype=\""+ascii2latex(s)+"\""; }
00420 void BibTexFactory::addVolume(QString &s) { entry+=",\nvolume="+s; }
00421 void BibTexFactory::addYear(QString &s) { entry+=",\nyear="+s; }
00422 void BibTexFactory::addKey(QString &s) { entry+=",\nkey=\""+ascii2latex(s)+"\""; }
00423 void BibTexFactory::addCrossRef(QString &s) { entry+=",\ncrossref=\""+ascii2latex(s)+"\""; }
00424 

Generated on Sat Mar 27 19:20:38 2004 for Literature by doxygen 1.3.6-20040222