The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
diafiltmgr.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * diafiltmgr.cpp - DiathekeFilterMgr
4  *
5  * $Id: diafiltmgr.cpp 3753 2020-07-10 09:32:46Z scribe $
6  *
7  * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org)
8  * CrossWire Bible Society
9  * P. O. Box 2528
10  * Tempe, AZ 85280-2528
11  *
12  * This program is free software; you can redistribute it and/or modify it
13  * under the terms of the GNU General Public License as published by the
14  * Free Software Foundation version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * General Public License for more details.
20  *
21  */
22 
23 #include <swmgr.h>
24 #include <swmodule.h>
25 
26 #include <thmlplain.h>
27 #include <thmlgbf.h>
28 #include <thmlosis.h>
29 #include <thmlhtml.h>
30 #include <thmlhtmlhref.h>
31 #include <thmlxhtml.h>
32 #include <thmllatex.h>
33 #include <thmlrtf.h>
34 #include <thmlwebif.h>
35 
36 #include <gbfplain.h>
37 #include <gbfthml.h>
38 #include <gbfosis.h>
39 #include <gbfhtml.h>
40 #include <gbfhtmlhref.h>
41 #include <gbfxhtml.h>
42 #include <gbflatex.h>
43 #include <gbfrtf.h>
44 #include <gbfwebif.h>
45 
46 #include <osisplain.h>
47 #include <osisosis.h>
48 #include <osisrtf.h>
49 #include <osishtmlhref.h>
50 #include <osisxhtml.h>
51 #include <osislatex.h>
52 #include <osiswebif.h>
53 
54 #include <teiplain.h>
55 #include <teirtf.h>
56 #include <teihtmlhref.h>
57 #include <teixhtml.h>
58 #include <teilatex.h>
59 
60 #include "diafiltmgr.h"
61 #include "thmlcgi.h"
62 #include "gbfcgi.h"
63 #include "osiscgi.h"
64 
66  : EncodingFilterMgr(enc) {
67 
68  markup = mark;
69 
71 }
72 
74  if (fromthml)
75  delete (fromthml);
76  if (fromgbf)
77  delete (fromgbf);
78  if (fromplain)
79  delete (fromplain);
80  if (fromosis)
81  delete (fromosis);
82  if (fromtei)
83  delete (fromtei);
84 }
85 
87  switch (module->getMarkup()) {
88  case FMT_THML:
89  if (fromthml)
90  module->addRenderFilter(fromthml);
91  break;
92  case FMT_GBF:
93  if (fromgbf)
94  module->addRenderFilter(fromgbf);
95  break;
96  case FMT_PLAIN:
97  if (fromplain)
98  module->addRenderFilter(fromplain);
99  break;
100  case FMT_OSIS:
101  if (fromosis)
102  module->addRenderFilter(fromosis);
103  break;
104  case FMT_TEI:
105  if (fromtei)
106  module->addRenderFilter(fromtei);
107  break;
108  }
109  EncodingFilterMgr::addRenderFilters(module, section);
110 }
111 
112 
113 char DiathekeFilterMgr::Markup(char mark) {
114  if (mark && mark != markup) {
115  markup = mark;
116  ModMap::const_iterator module;
117 
118  SWFilter * oldplain = fromplain;
119  SWFilter * oldthml = fromthml;
120  SWFilter * oldgbf = fromgbf;
121  SWFilter * oldosis = fromosis;
122  SWFilter * oldtei = fromtei;
123 
125 
126  for (module = getParentMgr()->Modules.begin(); module != getParentMgr()->Modules.end(); module++)
127  switch (module->second->getMarkup()) {
128  case FMT_THML:
129  if (oldthml != fromthml) {
130  if (oldthml) {
131  if (!fromthml) {
132  module->second->removeRenderFilter(oldthml);
133  }
134  else {
135  module->second->replaceRenderFilter(oldthml, fromthml);
136  }
137  }
138  else if (fromthml) {
139  module->second->addRenderFilter(fromthml);
140  }
141  }
142  break;
143  case FMT_GBF:
144  if (oldgbf != fromgbf) {
145  if (oldgbf) {
146  if (!fromgbf) {
147  module->second->removeRenderFilter(oldgbf);
148  }
149  else {
150  module->second->replaceRenderFilter(oldgbf, fromgbf);
151  }
152  }
153  else if (fromgbf) {
154  module->second->addRenderFilter(fromgbf);
155  }
156  break;
157  }
158  case FMT_PLAIN:
159  if (oldplain != fromplain) {
160  if (oldplain) {
161  if (!fromplain) {
162  module->second->removeRenderFilter(oldplain);
163  }
164  else {
165  module->second->replaceRenderFilter(oldplain, fromplain);
166  }
167  }
168  else if (fromplain) {
169  module->second->addRenderFilter(fromplain);
170  }
171  break;
172  }
173  case FMT_OSIS:
174  if (oldosis != fromosis) {
175  if (oldosis) {
176  if (!fromosis) {
177  module->second->removeRenderFilter(oldosis);
178  }
179  else {
180  module->second->replaceRenderFilter(oldosis, fromosis);
181  }
182  }
183  else if (fromosis) {
184  module->second->addRenderFilter(fromosis);
185  }
186  break;
187  }
188  case FMT_TEI:
189  if (oldtei != fromtei) {
190  if (oldtei) {
191  if (!fromtei) {
192  module->second->removeRenderFilter(oldtei);
193  }
194  else {
195  module->second->replaceRenderFilter(oldtei, fromtei);
196  }
197  }
198  else if (fromtei) {
199  module->second->addRenderFilter(fromtei);
200  }
201  break;
202  }
203  }
204 
205  if (oldthml)
206  delete oldthml;
207  if (oldgbf)
208  delete oldgbf;
209  if (oldplain)
210  delete oldplain;
211  if (oldosis)
212  delete oldosis;
213  if (oldtei)
214  delete oldtei;
215  }
216  return markup;
217 }
218 
220 
221  switch (markup) {
222  case FMT_INTERNAL:
223  fromplain = NULL;
224  fromthml = NULL;
225  fromgbf = NULL;
226  fromosis = NULL;
227  fromtei = NULL;
228  break;
229 
230  case FMT_CGI:
231  fromplain = NULL;
232  fromthml = new ThMLCGI();
233  fromgbf = new GBFCGI();
234  fromosis = new OSISCGI();
235  fromtei = NULL; // TODO: write TEICGI()
236  break;
237 
238  case FMT_PLAIN:
239  fromplain = NULL;
240  fromthml = new ThMLPlain();
241  fromgbf = new GBFPlain();
242  fromosis = new OSISPlain();
243  fromtei = new TEIPlain();
244  break;
245 
246  case FMT_THML:
247  fromplain = NULL;
248  fromthml = NULL;
249  fromgbf = new GBFThML();
250  fromosis = NULL;
251  fromtei = NULL;
252  break;
253 
254  case FMT_GBF:
255  fromplain = NULL;
256  fromthml = new ThMLGBF();
257  fromgbf = NULL;
258  fromosis = NULL;
259  fromtei = NULL;
260  break;
261 
262  case FMT_HTML:
263  fromplain = NULL;
264  fromthml = new ThMLHTML();
265  fromgbf = new GBFHTML();
266  fromosis = NULL;
267  fromtei = NULL;
268  break;
269 
270  case FMT_HTMLHREF:
271  fromplain = NULL;
272  fromthml = new ThMLHTMLHREF();
273  fromgbf = new GBFHTMLHREF();
274  fromosis = new OSISHTMLHREF();
275  fromtei = new TEIHTMLHREF();
276  break;
277 
278  case FMT_RTF:
279  fromplain = NULL;
280  fromthml = new ThMLRTF();
281  fromgbf = new GBFRTF();
282  fromosis = new OSISRTF();
283  fromtei = new TEIRTF();
284  break;
285 
286  case FMT_LATEX:
287  fromplain = NULL;
288  fromthml = new ThMLLaTeX();
289  fromgbf = new GBFLaTeX();
290  fromosis = new OSISLaTeX();
291  fromtei = new TEILaTeX();
292  break;
293 
294  case FMT_OSIS:
295  fromplain = NULL;
296  fromthml = new ThMLOSIS();
297  fromgbf = new GBFOSIS();
298  fromosis = new OSISOSIS();
299  fromtei = NULL;
300  break;
301 
302  case FMT_WEBIF:
303  fromplain = NULL;
304  fromthml = new ThMLWEBIF();
305  fromgbf = new GBFWEBIF();
306  fromosis = new OSISWEBIF();
307  fromtei = NULL;
308  break;
309 
310  case FMT_TEI:
311  fromplain = NULL;
312  fromthml = NULL;
313  fromgbf = NULL;
314  fromosis = NULL;
315  fromtei = NULL;
316  break;
317 
318  case FMT_XHTML:
319  fromplain = NULL;
320  fromthml = new ThMLXHTML();
321  fromgbf = new GBFXHTML();
322  fromosis = new OSISXHTML();
323  fromtei = new TEIXHTML();
324  break;
325  }
326 
327 }
Definition: gbfrtf.h:33
Definition: gbfcgi.h:33
#define FMT_INTERNAL
Definition: diafiltmgr.h:27
void CreateFilters(char markup)
Definition: diafiltmgr.cpp:219
SWFilter * fromgbf
Definition: diafiltmgr.h:38
char Markup(char m=FMT_UNKNOWN)
Definition: diafiltmgr.cpp:113
SWText * module
Definition: osis2mod.cpp:105
DiathekeFilterMgr(char markup=FMT_THML, char encoding=ENC_UTF8)
Definition: diafiltmgr.cpp:65
SWFilter * fromplain
Definition: diafiltmgr.h:39
SWFilter * fromosis
Definition: diafiltmgr.h:40
Definition: teirtf.h:33
return NULL
Definition: regex.c:7953
#define FMT_CGI
Definition: diafiltmgr.h:26
virtual void addRenderFilters(SWModule *module, ConfigEntMap &section)
Definition: diafiltmgr.cpp:86
virtual void addRenderFilters(SWModule *module, ConfigEntMap &section)
Definition: swfiltermgr.cpp:72
virtual SWMgr * getParentMgr()
Definition: swfiltermgr.cpp:43
SWORD_NAMESPACE_START typedef multimapwithdefault< SWBuf, SWBuf, std::less< SWBuf > > ConfigEntMap
Definition: swconfig.h:35
SWFilter * fromthml
Definition: diafiltmgr.h:37
SWFilter * fromtei
Definition: diafiltmgr.h:41