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 #include <gbfosis.h>
00034 #include <thmlosis.h>
00035 
00036 #include <markupfiltmgr.h>
00037 
00038 #include <swmgr.h>
00039 
00040 
00041 /******************************************************************************
00042  * MarkupFilterMgr Constructor - initializes instance of MarkupFilterMgr
00043  *
00044  * ENT:
00045  *      enc - Encoding format to emit
00046  *      mark - Markup format to emit
00047  */
00048 
00049 MarkupFilterMgr::MarkupFilterMgr (char mark, char enc)
00050                    : EncodingFilterMgr(enc) {
00051 
00052         markup = mark;
00053 
00054         CreateFilters(markup);
00055 }
00056 
00057 
00058 /******************************************************************************
00059  * MarkupFilterMgr Destructor - Cleans up instance of MarkupFilterMgr
00060  */
00061 
00062 MarkupFilterMgr::~MarkupFilterMgr() {
00063         if (fromthml)
00064                 delete (fromthml);
00065         if (fromgbf)
00066                 delete (fromgbf);
00067         if (fromplain)
00068                 delete (fromplain);
00069         if (fromosis)
00070                 delete (fromosis);
00071 }
00072 
00073 /******************************************************************************
00074  * MarkupFilterMgr::Markup      - sets/gets markup
00075  *
00076  * ENT: mark    - new encoding or 0 to simply get the current markup
00077  *
00078  * RET: markup
00079  */
00080 char MarkupFilterMgr::Markup(char mark) {
00081         if (mark && mark != markup) {
00082                 markup = mark;
00083                 ModMap::const_iterator module;
00084 
00085                 SWFilter * oldplain = fromplain;
00086                 SWFilter * oldthml = fromthml;
00087                 SWFilter * oldgbf = fromgbf;
00088                 SWFilter * oldosis = fromosis;
00089 
00090                 CreateFilters(markup);
00091 
00092                 for (module = getParentMgr()->Modules.begin(); module != getParentMgr()->Modules.end(); module++)
00093                         switch (module->second->Markup()) {
00094                         case FMT_THML:
00095                                 if (oldthml != fromthml) {
00096                                         if (oldthml) {
00097                                                 if (!fromthml) {
00098                                                         module->second->RemoveRenderFilter(oldthml);
00099                                                 }
00100                                                 else {
00101                                                         module->second->ReplaceRenderFilter(oldthml, fromthml);
00102                                                 }
00103                                         }
00104                                         else if (fromthml) {
00105                                                 module->second->AddRenderFilter(fromthml);
00106                                         }
00107                                 }
00108                                 break;
00109                         case FMT_GBF:
00110                                 if (oldgbf != fromgbf) {
00111                                         if (oldgbf) {
00112                                                 if (!fromgbf) {
00113                                                         module->second->RemoveRenderFilter(oldgbf);
00114                                                 }
00115                                                 else {
00116                                                         module->second->ReplaceRenderFilter(oldgbf, fromgbf);
00117                                                 }
00118                                         }
00119                                         else if (fromgbf) {
00120                                                 module->second->AddRenderFilter(fromgbf);
00121                                         }
00122                                         break;
00123                                 }
00124                         case FMT_PLAIN:
00125                                 if (oldplain != fromplain) {
00126                                         if (oldplain) {
00127                                                 if (!fromplain) {
00128                                                         module->second->RemoveRenderFilter(oldplain);
00129                                                 }
00130                                                 else {
00131                                                         module->second->ReplaceRenderFilter(oldplain, fromplain);
00132                                                 }
00133                                         }
00134                                         else if (fromplain) {
00135                                                 module->second->AddRenderFilter(fromplain);
00136                                         }
00137                                         break;
00138                                 }
00139                         case FMT_OSIS:
00140                                 if (oldosis != fromosis) {
00141                                         if (oldosis) {
00142                                                 if (!fromosis) {
00143                                                         module->second->RemoveRenderFilter(oldosis);
00144                                                 }
00145                                                 else {
00146                                                         module->second->ReplaceRenderFilter(oldosis, fromosis);
00147                                                 }
00148                                         }
00149                                         else if (fromosis) {
00150                                                 module->second->AddRenderFilter(fromosis);
00151                                         }
00152                                         break;
00153                                 }
00154                         }
00155 
00156                 if (oldthml)
00157                         delete oldthml;
00158                 if (oldgbf)
00159                         delete oldgbf;
00160                 if (oldplain)
00161                         delete oldplain;
00162                 if (oldosis)
00163                         delete oldosis;
00164         }
00165         return markup;
00166 }
00167 
00168 void MarkupFilterMgr::AddRenderFilters(SWModule *module, ConfigEntMap &section) {
00169         switch (module->Markup()) {
00170         case FMT_THML:
00171                 if (fromthml)
00172                         module->AddRenderFilter(fromthml);
00173                 break;
00174         case FMT_GBF:
00175                 if (fromgbf)
00176                         module->AddRenderFilter(fromgbf);
00177                 break;
00178         case FMT_PLAIN:
00179                 if (fromplain)
00180                         module->AddRenderFilter(fromplain);
00181                 break;
00182         case FMT_OSIS:
00183                 if (fromosis)
00184                         module->AddRenderFilter(fromosis);
00185                 break;
00186         }
00187 }
00188 
00189 void MarkupFilterMgr::CreateFilters(char markup) {
00190 
00191                 switch (markup) {
00192                 case FMT_PLAIN:
00193                         fromplain = NULL;
00194                         fromthml = new ThMLPlain();
00195                         fromgbf = new GBFPlain();
00196                         fromosis = NULL;
00197                         break;
00198                 case FMT_THML:
00199                         fromplain = NULL;
00200                         fromthml = NULL;
00201                         fromgbf = new GBFThML();
00202                         fromosis = NULL;
00203                         break;
00204                 case FMT_GBF:
00205                         fromplain = NULL;
00206                         fromthml = new ThMLGBF();
00207                         fromgbf = NULL;
00208                         fromosis = NULL;
00209                         break;
00210                 case FMT_HTML:
00211                         fromplain = new PLAINHTML();
00212                         fromthml = new ThMLHTML();
00213                         fromgbf = new GBFHTML();
00214                         fromosis = NULL;
00215                         break;
00216                 case FMT_HTMLHREF:
00217                         fromplain = NULL;
00218                         fromthml = new ThMLHTMLHREF();
00219                         fromgbf = new GBFHTMLHREF();
00220                         fromosis = NULL;
00221                         break;
00222                 case FMT_RTF:
00223                         fromplain = NULL;
00224                         fromthml = new ThMLRTF();
00225                         fromgbf = new GBFRTF();
00226                         fromosis = NULL;
00227                         break;
00228                 case FMT_OSIS:
00229                         fromplain = NULL;
00230                         fromthml = new ThMLOSIS();
00231                         fromgbf = new GBFOSIS();
00232                         fromosis = NULL;
00233                         break;
00234                 }
00235 
00236 }

Generated on Thu Jun 20 22:12:59 2002 for The Sword Project by doxygen1.2.15