00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00041
00042
00043
00044
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
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
00073
00074
00075
00076
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 §ion) {
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 }