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