Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

markupfiltmgr.cpp

00001 /******************************************************************************
00002  *  swmarkupmgr.cpp   - implementaion of class MarkupFilterMgr, subclass of
00003  *                        used to transcode all module text to a requested
00004  *                        markup.
00005  *
00006  * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
00007  *      CrossWire Bible Society
00008  *      P. O. Box 2528
00009  *      Tempe, AZ  85280-2528
00010  *
00011  * This program is free software; you can redistribute it and/or modify it
00012  * under the terms of the GNU General Public License as published by the
00013  * Free Software Foundation version 2.
00014  *
00015  * This program is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * General Public License for more details.
00019  *
00020  */
00021 
00022 #include <thmlplain.h>
00023 #include <gbfplain.h>
00024 #include <thmlgbf.h>
00025 #include <gbfthml.h>
00026 #include <thmlhtml.h>
00027 #include <gbfhtml.h>
00028 #include <plainhtml.h>
00029 #include <thmlhtmlhref.h>
00030 #include <gbfhtmlhref.h>
00031 #include <thmlrtf.h>
00032 #include <gbfrtf.h>
00033 
00034 #include <markupfiltmgr.h>
00035 
00036 #include <swmgr.h>
00037 
00038 
00039 /******************************************************************************
00040  * MarkupFilterMgr Constructor - initializes instance of MarkupFilterMgr
00041  *
00042  * ENT:
00043  *      enc - Encoding format to emit
00044  *      mark - Markup format to emit
00045  */
00046 
00047 MarkupFilterMgr::MarkupFilterMgr (char mark, char enc)
00048                    : EncodingFilterMgr(enc) {
00049 
00050         markup = mark;
00051 
00052         CreateFilters(markup);
00053 }
00054 
00055 
00056 /******************************************************************************
00057  * MarkupFilterMgr Destructor - Cleans up instance of MarkupFilterMgr
00058  */
00059 
00060 MarkupFilterMgr::~MarkupFilterMgr() {
00061         if (fromthml)
00062                 delete (fromthml);
00063         if (fromgbf)
00064                 delete (fromgbf);
00065         if (fromplain)
00066                 delete (fromplain);
00067         if (fromosis)
00068                 delete (fromosis);
00069 }
00070 
00071 /******************************************************************************
00072  * MarkupFilterMgr::Markup      - sets/gets markup
00073  *
00074  * ENT: mark    - new encoding or 0 to simply get the current markup
00075  *
00076  * RET: markup
00077  */
00078 char MarkupFilterMgr::Markup(char mark) {
00079         if (mark && mark != markup) {
00080                 markup = mark;
00081                 ModMap::const_iterator module;
00082 
00083                 SWFilter * oldplain = fromplain;
00084                 SWFilter * oldthml = fromthml;
00085                 SWFilter * oldgbf = fromgbf;
00086                 SWFilter * oldosis = fromosis;
00087 
00088                 CreateFilters(markup);
00089 
00090                 for (module = getParentMgr()->Modules.begin(); module != getParentMgr()->Modules.end(); module++)
00091                         switch (module->second->Markup()) {
00092                         case FMT_THML:
00093                                 if (oldthml != fromthml) {
00094                                         if (oldthml) {
00095                                                 if (!fromthml) {
00096                                                         module->second->RemoveRenderFilter(oldthml);
00097                                                 }
00098                                                 else {
00099                                                         module->second->ReplaceRenderFilter(oldthml, fromthml);
00100                                                 }
00101                                         }
00102                                         else if (fromthml) {
00103                                                 module->second->AddRenderFilter(fromthml);
00104                                         }
00105                                 }
00106                                 break;
00107                         case FMT_GBF:
00108                                 if (oldgbf != fromgbf) {
00109                                         if (oldgbf) {
00110                                                 if (!fromgbf) {
00111                                                         module->second->RemoveRenderFilter(oldgbf);
00112                                                 }
00113                                                 else {
00114                                                         module->second->ReplaceRenderFilter(oldgbf, fromgbf);
00115                                                 }
00116                                         }
00117                                         else if (fromgbf) {
00118                                                 module->second->AddRenderFilter(fromgbf);
00119                                         }
00120                                         break;
00121                                 }
00122                         case FMT_PLAIN:
00123                                 if (oldplain != fromplain) {
00124                                         if (oldplain) {
00125                                                 if (!fromplain) {
00126                                                         module->second->RemoveRenderFilter(oldplain);
00127                                                 }
00128                                                 else {
00129                                                         module->second->ReplaceRenderFilter(oldplain, fromplain);
00130                                                 }
00131                                         }
00132                                         else if (fromplain) {
00133                                                 module->second->AddRenderFilter(fromplain);
00134                                         }
00135                                         break;
00136                                 }
00137                         case FMT_OSIS:
00138                                 if (oldosis != fromosis) {
00139                                         if (oldosis) {
00140                                                 if (!fromosis) {
00141                                                         module->second->RemoveRenderFilter(oldosis);
00142                                                 }
00143                                                 else {
00144                                                         module->second->ReplaceRenderFilter(oldosis, fromosis);
00145                                                 }
00146                                         }
00147                                         else if (fromosis) {
00148                                                 module->second->AddRenderFilter(fromosis);
00149                                         }
00150                                         break;
00151                                 }
00152                         }
00153 
00154                 if (oldthml)
00155                         delete oldthml;
00156                 if (oldgbf)
00157                         delete oldgbf;
00158                 if (oldplain)
00159                         delete oldplain;
00160                 if (oldosis)
00161                         delete oldosis;
00162         }
00163         return markup;
00164 }
00165 
00166 void MarkupFilterMgr::AddRenderFilters(SWModule *module, ConfigEntMap &section) {
00167         switch (module->Markup()) {
00168         case FMT_THML:
00169                 if (fromthml)
00170                         module->AddRenderFilter(fromthml);
00171                 break;
00172         case FMT_GBF:
00173                 if (fromgbf)
00174                         module->AddRenderFilter(fromgbf);
00175                 break;
00176         case FMT_PLAIN:
00177                 if (fromplain)
00178                         module->AddRenderFilter(fromplain);
00179                 break;
00180         case FMT_OSIS:
00181                 if (fromosis)
00182                         module->AddRenderFilter(fromosis);
00183                 break;
00184         }
00185 }
00186 
00187 void MarkupFilterMgr::CreateFilters(char markup) {
00188 
00189                 switch (markup) {
00190                 case FMT_PLAIN:
00191                         fromplain = NULL;
00192                         fromthml = new ThMLPlain();
00193                         fromgbf = new GBFPlain();
00194                         fromosis = NULL;
00195                         break;
00196                 case FMT_THML:
00197                         fromplain = NULL;
00198                         fromthml = NULL;
00199                         fromgbf = new GBFThML();
00200                         fromosis = NULL;
00201                         break;
00202                 case FMT_GBF:
00203                         fromplain = NULL;
00204                         fromthml = new ThMLGBF();
00205                         fromgbf = NULL;
00206                         fromosis = NULL;
00207                         break;
00208                 case FMT_HTML:
00209                         fromplain = new PLAINHTML();
00210                         fromthml = new ThMLHTML();
00211                         fromgbf = new GBFHTML();
00212                         fromosis = NULL;
00213                         break;
00214                 case FMT_HTMLHREF:
00215                         fromplain = NULL;
00216                         fromthml = new ThMLHTMLHREF();
00217                         fromgbf = new GBFHTMLHREF();
00218                         fromosis = NULL;
00219                         break;
00220                 case FMT_RTF:
00221                         fromplain = NULL;
00222                         fromthml = new ThMLRTF();
00223                         fromgbf = new GBFRTF();
00224                         fromosis = NULL;
00225                         break;
00226                 case FMT_OSIS:
00227                         fromplain = NULL;
00228                         fromthml = NULL;
00229                         fromgbf = NULL;
00230                         fromosis = NULL;
00231                         break;
00232                 }
00233 
00234 }

Generated on Wed Apr 3 22:34:14 2002 for The Sword Project by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002