The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OSISHTMLHREF Class Reference

#include <osishtmlhref.h>

+ Inheritance diagram for OSISHTMLHREF:
+ Collaboration diagram for OSISHTMLHREF:

Classes

class  MyUserData
 
class  TagStacks
 

Public Member Functions

virtual const char * getHeader () const
 
 OSISHTMLHREF ()
 
virtual char processText (SWBuf &text, const SWKey *key=0, const SWModule *module=0)
 
void setMorphFirst (bool val=true)
 
void setRenderNoteNumbers (bool val=true)
 

Protected Member Functions

void addAllowedEscapeString (const char *findString)
 
void addEscapeStringSubstitute (const char *findString, const char *replaceString)
 
void addTokenSubstitute (const char *findString, const char *replaceString)
 
void appendEscapeString (SWBuf &buf, const char *escString)
 
virtual BasicFilterUserDatacreateUserData (const SWModule *module, const SWKey *key)
 
virtual bool handleEscapeString (SWBuf &buf, const char *escString, BasicFilterUserData *userData)
 
virtual bool handleNumericEscapeString (SWBuf &buf, const char *escString)
 
virtual bool handleToken (SWBuf &buf, const char *token, BasicFilterUserData *userData)
 
bool passAllowedEscapeString (SWBuf &buf, const char *escString)
 
virtual bool processStage (char, SWBuf &, char *&, BasicFilterUserData *)
 
void removeAllowedEscapeString (const char *findString)
 
void removeEscapeStringSubstitute (const char *findString)
 
void removeTokenSubstitute (const char *findString)
 
void setEscapeEnd (const char *escEnd)
 
void setEscapeStart (const char *escStart)
 
void setEscapeStringCaseSensitive (bool val)
 
void setPassThruNumericEscapeString (bool val)
 
void setPassThruUnknownEscapeString (bool val)
 
void setPassThruUnknownToken (bool val)
 
virtual void setStageProcessing (char stages)
 
void setTokenCaseSensitive (bool val)
 
void setTokenEnd (const char *tokenEnd)
 
void setTokenStart (const char *tokenStart)
 
bool substituteEscapeString (SWBuf &buf, const char *escString)
 
bool substituteToken (SWBuf &buf, const char *token)
 

Static Protected Attributes

static const char FINALIZE = 8
 
static const char INITIALIZE = 1
 
static const char POSTCHAR = 4
 
static const char PRECHAR = 2
 

Private Attributes

bool morphFirst
 
bool renderNoteNumbers
 

Detailed Description

this filter converts OSIS text to HTML text with hrefs

Definition at line 33 of file osishtmlhref.h.

Constructor & Destructor Documentation

OSISHTMLHREF::OSISHTMLHREF ( )

Definition at line 133 of file osishtmlhref.cpp.

133  {
134  setTokenStart("<");
135  setTokenEnd(">");
136 
137  setEscapeStart("&");
138  setEscapeEnd(";");
139 
142 
143  addAllowedEscapeString("quot");
144  addAllowedEscapeString("apos");
145  addAllowedEscapeString("amp");
148 
149  setTokenCaseSensitive(true);
150 
151  // addTokenSubstitute("lg", "<br />");
152  // addTokenSubstitute("/lg", "<br />");
153 
154  morphFirst = false;
155  renderNoteNumbers = false;
156 }
void setTokenEnd(const char *tokenEnd)
void addAllowedEscapeString(const char *findString)
void setTokenCaseSensitive(bool val)
bool renderNoteNumbers
Definition: osishtmlhref.h:36
void setEscapeStart(const char *escStart)
void setTokenStart(const char *tokenStart)
void setPassThruNumericEscapeString(bool val)
void setEscapeStringCaseSensitive(bool val)
void setEscapeEnd(const char *escEnd)

Member Function Documentation

void SWBasicFilter::addAllowedEscapeString ( const char *  findString)
protectedinherited

Registers an esc control sequence that can pass unchanged

Definition at line 156 of file swbasicfilter.cpp.

156  {
157  char *buf = 0;
158 
159  if (!escStringCaseSensitive) {
160  stdstr(&buf, findString);
161  toupperstr(buf);
162  p->escPassSet.insert(StringSet::value_type(buf));
163  delete [] buf;
164  }
165  else p->escPassSet.insert(StringSet::value_type(findString));
166 }
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
bool escStringCaseSensitive
Definition: swbasicfilter.h:74
char * toupperstr(char *t, unsigned int max=0)
Definition: stringmgr.h:107
Private * p
Definition: swbasicfilter.h:82
void SWBasicFilter::addEscapeStringSubstitute ( const char *  findString,
const char *  replaceString 
)
protectedinherited

Registers an esc control sequence

Definition at line 176 of file swbasicfilter.cpp.

176  {
177  char *buf = 0;
178 
179  if (!escStringCaseSensitive) {
180  stdstr(&buf, findString);
181  toupperstr(buf);
182  p->escSubMap.insert(DualStringMap::value_type(buf, replaceString));
183  delete [] buf;
184  }
185  else p->escSubMap.insert(DualStringMap::value_type(findString, replaceString));
186 }
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
bool escStringCaseSensitive
Definition: swbasicfilter.h:74
char * toupperstr(char *t, unsigned int max=0)
Definition: stringmgr.h:107
Private * p
Definition: swbasicfilter.h:82
void SWBasicFilter::addTokenSubstitute ( const char *  findString,
const char *  replaceString 
)
protectedinherited

Registers a simple token substitutions. Usually called from the c-tor of a subclass

Definition at line 136 of file swbasicfilter.cpp.

136  {
137  char *buf = 0;
138 
139  if (!tokenCaseSensitive) {
140  stdstr(&buf, findString);
141  toupperstr(buf);
142  p->tokenSubMap[buf] = replaceString;
143  delete [] buf;
144  }
145  else p->tokenSubMap[findString] = replaceString;
146 }
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
bool tokenCaseSensitive
Definition: swbasicfilter.h:75
DualStringMap tokenSubMap
char * toupperstr(char *t, unsigned int max=0)
Definition: stringmgr.h:107
Private * p
Definition: swbasicfilter.h:82
void SWBasicFilter::appendEscapeString ( SWBuf buf,
const char *  escString 
)
protectedinherited

This appends escString to buf as an entity

Definition at line 216 of file swbasicfilter.cpp.

216  {
217  buf += escStart;
218  buf += escString;
219  buf += escEnd;
220 }
virtual BasicFilterUserData* OSISHTMLHREF::createUserData ( const SWModule module,
const SWKey key 
)
inlineprotectedvirtual

Reimplemented from SWBasicFilter.

Definition at line 58 of file osishtmlhref.h.

58  {
59  return new MyUserData(module, key);
60  }
virtual const char* SWFilter::getHeader ( ) const
inlinevirtualinherited

This method can supply a header associated with the processing done with this filter. A typical example is a suggested CSS style block for classed containers.

Reimplemented in OSISLaTeX, OSISXHTML, ThMLLaTeX, ThMLXHTML, TEIXHTML, GBFLaTeX, and GBFXHTML.

Definition at line 62 of file swfilter.h.

62 { return ""; }
bool SWBasicFilter::handleEscapeString ( SWBuf buf,
const char *  escString,
BasicFilterUserData userData 
)
protectedvirtualinherited

This function is called for every escape sequence encountered in the input text.

Parameters
bufthe output buffer
escStringthe escape sequence (e.g. "amp" for &amp;)
userDatauser storage space for data transient to 1 full buffer parse
Returns
false if was not handled and should be handled in
subclasses should return true if they handled the esc seq, or false if they did not.

Definition at line 286 of file swbasicfilter.cpp.

286  {
287  return substituteEscapeString(buf, escString);
288 }
bool substituteEscapeString(SWBuf &buf, const char *escString)
bool SWBasicFilter::handleNumericEscapeString ( SWBuf buf,
const char *  escString 
)
protectedvirtualinherited

This function is called for all numeric escape sequences. If passThrough

Parameters
bufthe output buffer
escStringthe escape sequence (e.g. "#235" for &235;)
Returns
subclasses should return true if they handled the esc seq, or false if they did not.

Definition at line 244 of file swbasicfilter.cpp.

244  {
245  if (passThruNumericEsc) {
246  appendEscapeString(buf, escString);
247  return true;
248  }
249  return false;
250 }
bool passThruNumericEsc
Definition: swbasicfilter.h:78
void appendEscapeString(SWBuf &buf, const char *escString)
bool OSISHTMLHREF::handleToken ( SWBuf buf,
const char *  token,
BasicFilterUserData userData 
)
protectedvirtual

This function is called for every token encountered in the input text.

Parameters
bufthe output buffer
tokenthe token (e.g. "p align='left'"
userDatauser storage space for data transient to 1 full buffer parse
Returns
subclasses should return true if they handled the token, or false if they did not.

Reimplemented from SWBasicFilter.

Definition at line 159 of file osishtmlhref.cpp.

159  {
160  MyUserData *u = (MyUserData *)userData;
161  SWBuf scratch;
162  bool sub = (u->suspendTextPassThru) ? substituteToken(scratch, token) : substituteToken(buf, token);
163  if (!sub) {
164  // manually process if it wasn't a simple substitution
165  XMLTag tag(token);
166 
167  // <w> tag
168  if (!strcmp(tag.getName(), "w")) {
169 
170  // start <w> tag
171  if ((!tag.isEmpty()) && (!tag.isEndTag())) {
172  u->w = token;
173  }
174 
175  // end or empty <w> tag
176  else {
177  bool endTag = tag.isEndTag();
178  SWBuf lastText;
179  //bool show = true; // to handle unplaced article in kjv2003-- temporary till combined
180 
181  if (endTag) {
182  tag = u->w.c_str();
183  lastText = u->lastTextNode.c_str();
184  }
185  else lastText = "stuff";
186 
187  const char *attrib;
188  const char *val;
189  if ((attrib = tag.getAttribute("xlit"))) {
190  val = strchr(attrib, ':');
191  val = (val) ? (val + 1) : attrib;
192  outText(" ", buf, u);
193  outText(val, buf, u);
194  }
195  if ((attrib = tag.getAttribute("gloss"))) {
196  // I'm sure this is not the cleanest way to do it, but it gets the job done
197  // for rendering ruby chars properly ^_^
198  buf -= lastText.length();
199 
200  outText("<ruby><rb>", buf, u);
201  outText(lastText, buf, u);
202  outText("</rb><rp>(</rp><rt>", buf, u);
203  val = strchr(attrib, ':');
204  val = (val) ? (val + 1) : attrib;
205  outText(val, buf, u);
206  outText("</rt><rp>)</rp></ruby>", buf, u);
207  }
208  if (!morphFirst) {
209  processLemma(u->suspendTextPassThru, tag, buf);
210  processMorph(u->suspendTextPassThru, tag, buf);
211  }
212  else {
213  processMorph(u->suspendTextPassThru, tag, buf);
214  processLemma(u->suspendTextPassThru, tag, buf);
215  }
216  if ((attrib = tag.getAttribute("POS"))) {
217  val = strchr(attrib, ':');
218  val = (val) ? (val + 1) : attrib;
219  outText(" ", buf, u);
220  outText(val, buf, u);
221  }
222 
223  /*if (endTag)
224  buf += "}";*/
225  }
226  }
227 
228  // <note> tag
229  else if (!strcmp(tag.getName(), "note")) {
230  if (!tag.isEndTag()) {
231  SWBuf type = tag.getAttribute("type");
232  bool strongsMarkup = (type == "x-strongsMarkup" || type == "strongsMarkup"); // the latter is deprecated
233  if (strongsMarkup) {
234  tag.setEmpty(false); // handle bug in KJV2003 module where some note open tags were <note ... />
235  }
236 
237  if (!tag.isEmpty()) {
238 
239  if (!strongsMarkup) { // leave strong's markup notes out, in the future we'll probably have different option filters to turn different note types on or off
240  SWBuf footnoteNumber = tag.getAttribute("swordFootnote");
241  SWBuf noteName = tag.getAttribute("n");
242  char ch = ((tag.getAttribute("type") && ((!strcmp(tag.getAttribute("type"), "crossReference")) || (!strcmp(tag.getAttribute("type"), "x-cross-ref")))) ? 'x':'n');
243 
244  u->inXRefNote = true; // Why this change? Ben Morgan: Any note can have references in, so we need to set this to true for all notes
245 // u->inXRefNote = (ch == 'x');
246  buf.appendFormatted("<a href=\"passagestudy.jsp?action=showNote&type=%c&value=%s&module=%s&passage=%s\"><small><sup class=\"%c\">*%c%s</sup></small></a>",
247  ch,
248  URL::encode(footnoteNumber.c_str()).c_str(),
249  URL::encode(u->version.c_str()).c_str(),
250  URL::encode(u->vkey ? u->vkey->getText() : u->key->getText()).c_str(),
251  ch,
252  ch,
253  (renderNoteNumbers ? noteName.c_str() : ""));
254  }
255  }
256  u->suspendTextPassThru = (++u->suspendLevel);
257  }
258  if (tag.isEndTag()) {
259  u->suspendTextPassThru = (--u->suspendLevel);
260  u->inXRefNote = false;
261  u->lastSuspendSegment = ""; // fix/work-around for nasb divineName in note bug
262  }
263  }
264 
265  // <p> paragraph and <lg> linegroup tags
266  else if (!strcmp(tag.getName(), "p") || !strcmp(tag.getName(), "lg")) {
267  if ((!tag.isEndTag()) && (!tag.isEmpty())) { // non-empty start tag
268  outText("<!P><br />", buf, u);
269  }
270  else if (tag.isEndTag()) { // end tag
271  outText("<!/P><br />", buf, u);
272  userData->supressAdjacentWhitespace = true;
273  }
274  else { // empty paragraph break marker
275  outText("<!P><br />", buf, u);
276  userData->supressAdjacentWhitespace = true;
277  }
278  }
279 
280  // Milestoned paragraphs, created by osis2mod
281  // <div type="paragraph" sID.../>
282  // <div type="paragraph" eID.../>
283  else if (tag.isEmpty() && !strcmp(tag.getName(), "div") && tag.getAttribute("type") && (!strcmp(tag.getAttribute("type"), "x-p") || !strcmp(tag.getAttribute("type"), "paragraph"))) {
284  // <div type="paragraph" sID... />
285  if (tag.getAttribute("sID")) { // non-empty start tag
286  outText("<!P><br />", buf, u);
287  }
288  // <div type="paragraph" eID... />
289  else if (tag.getAttribute("eID")) {
290  outText("<!/P><br />", buf, u);
291  userData->supressAdjacentWhitespace = true;
292  }
293  }
294 
295  // <reference> tag
296  else if (!strcmp(tag.getName(), "reference")) {
297  if (!u->inXRefNote) { // only show these if we're not in an xref note
298  if (!tag.isEndTag()) {
299  SWBuf target;
300  SWBuf work;
301  SWBuf ref;
302  bool is_scripRef = false;
303 
304  target = tag.getAttribute("osisRef");
305  const char* the_ref = strchr(target, ':');
306 
307  if(!the_ref) {
308  // No work
309  ref = target;
310  is_scripRef = true;
311  }
312  else {
313  // Compensate for starting :
314  ref = the_ref + 1;
315 
316  int size = (int)(target.size() - ref.size() - 1);
317  work.setSize(size);
318  strncpy(work.getRawData(), target, size);
319 
320  // For Bible:Gen.3.15 or Bible.vulgate:Gen.3.15
321  if(!strncmp(work, "Bible", 5))
322  is_scripRef = true;
323  }
324 
325  if(is_scripRef)
326  {
327  buf.appendFormatted("<a href=\"passagestudy.jsp?action=showRef&type=scripRef&value=%s&module=\">",
328  URL::encode(ref.c_str()).c_str()
329 // (work.size()) ? URL::encode(work.c_str()).c_str() : "")
330  );
331  }
332  else
333  {
334  // Dictionary link, or something
335  buf.appendFormatted("<a href=\"sword://%s/%s\">",
336  URL::encode(work.c_str()).c_str(),
337  URL::encode(ref.c_str()).c_str()
338  );
339  }
340  }
341  else {
342  outText("</a>", buf, u);
343  }
344  }
345  }
346 
347  // <l> poetry, etc
348  else if (!strcmp(tag.getName(), "l")) {
349  // end line marker
350  if (tag.getAttribute("eID")) {
351  outText("<br />", buf, u);
352  }
353  // <l/> without eID or sID
354  // Note: this is improper osis. This should be <lb/>
355  else if (tag.isEmpty() && !tag.getAttribute("sID")) {
356  outText("<br />", buf, u);
357  }
358  // end of the line
359  else if (tag.isEndTag()) {
360  outText("<br />", buf, u);
361  }
362  }
363 
364  // <lb.../>
365  else if (!strcmp(tag.getName(), "lb") && (!tag.getAttribute("type") || strcmp(tag.getAttribute("type"), "x-optional"))) {
366  outText("<br />", buf, u);
367  userData->supressAdjacentWhitespace = true;
368  }
369  // <milestone type="line"/>
370  // <milestone type="x-p"/>
371  // <milestone type="cQuote" marker="x"/>
372  else if ((!strcmp(tag.getName(), "milestone")) && (tag.getAttribute("type"))) {
373  if (!strcmp(tag.getAttribute("type"), "line")) {
374  outText("<br />", buf, u);
375  if (tag.getAttribute("subType") && !strcmp(tag.getAttribute("subType"), "x-PM")) {
376  outText("<br />", buf, u);
377  }
378  userData->supressAdjacentWhitespace = true;
379  }
380  else if (!strcmp(tag.getAttribute("type"),"x-p")) {
381  if (tag.getAttribute("marker"))
382  outText(tag.getAttribute("marker"), buf, u);
383  else outText("<!p>", buf, u);
384  }
385  else if (!strcmp(tag.getAttribute("type"), "cQuote")) {
386  const char *tmp = tag.getAttribute("marker");
387  bool hasMark = tmp;
388  SWBuf mark = tmp;
389  tmp = tag.getAttribute("level");
390  int level = (tmp) ? atoi(tmp) : 1;
391 
392  // first check to see if we've been given an explicit mark
393  if (hasMark)
394  outText(mark, buf, u);
395  // finally, alternate " and ', if config says we should supply a mark
396  else if (u->osisQToTick)
397  outText((level % 2) ? '\"' : '\'', buf, u);
398  }
399  }
400 
401  // <title>
402  else if (!strcmp(tag.getName(), "title")) {
403  if ((!tag.isEndTag()) && (!tag.isEmpty())) {
404  outText("<b>", buf, u);
405  }
406  else if (tag.isEndTag()) {
407  outText("</b><br />", buf, u);
408  }
409  }
410 
411  // <list>
412  else if (!strcmp(tag.getName(), "list")) {
413  if((!tag.isEndTag()) && (!tag.isEmpty())) {
414  outText("<ul>", buf, u);
415  }
416  else if (tag.isEndTag()) {
417  outText("</ul>", buf, u);
418  }
419  }
420 
421  // <item>
422  else if (!strcmp(tag.getName(), "item")) {
423  if((!tag.isEndTag()) && (!tag.isEmpty())) {
424  outText("<li>", buf, u);
425  }
426  else if (tag.isEndTag()) {
427  outText("</li>", buf, u);
428  }
429  }
430  // <catchWord> & <rdg> tags (italicize)
431  else if (!strcmp(tag.getName(), "rdg") || !strcmp(tag.getName(), "catchWord")) {
432  if ((!tag.isEndTag()) && (!tag.isEmpty())) {
433  outText("<i>", buf, u);
434  }
435  else if (tag.isEndTag()) {
436  outText("</i>", buf, u);
437  }
438  }
439 
440  // divineName
441  else if (!strcmp(tag.getName(), "divineName")) {
442  if ((!tag.isEndTag()) && (!tag.isEmpty())) {
443  u->suspendTextPassThru = (++u->suspendLevel);
444  }
445  else if (tag.isEndTag()) {
446  SWBuf lastText = u->lastSuspendSegment.c_str();
447  u->suspendTextPassThru = (--u->suspendLevel);
448  if (lastText.size()) {
449  lastText.toUpper();
450  scratch.setFormatted("%c<font size=\"-1\">%s</font>", lastText[0], lastText.c_str()+1);
451 
452  const unsigned char *tmpBuf = (const unsigned char *)lastText.c_str();
453  getUniCharFromUTF8(&tmpBuf);
454  int char_length = (int)(tmpBuf - (const unsigned char *)lastText.c_str());
455  scratch.setFormatted("%.*s<font size=\"-1\">%s</font>",
456  char_length,
457  lastText.c_str(),
458  lastText.c_str() + char_length
459  );
460 
461  outText(scratch.c_str(), buf, u);
462  }
463  }
464  }
465 
466  // <hi> text highlighting
467  else if (!strcmp(tag.getName(), "hi")) {
468  SWBuf type = tag.getAttribute("type");
469  // handle tei rend attribute
470  if (!type.length()) type = tag.getAttribute("rend");
471  if ((!tag.isEndTag()) && (!tag.isEmpty())) {
472  if (type == "bold" || type == "b" || type == "x-b") {
473  outText("<b>", buf, u);
474  }
475  else if (type == "ol" || type == "overline" || type == "x-overline") {
476  outText("<span style=\"text-decoration:overline\">", buf, u);
477  }
478  else if (type == "super") {
479  outText("<sup>", buf, u);
480  }
481  else if (type == "sub") {
482  outText("<sub>", buf, u);
483  }
484  else { // all other types
485  outText("<i>", buf, u);
486  }
487  u->tagStacks->hiStack.push(tag.toString());
488  }
489  else if (tag.isEndTag()) {
490  SWBuf type = "";
491  if (!u->tagStacks->hiStack.empty()) {
492  XMLTag tag(u->tagStacks->hiStack.top());
493  u->tagStacks->hiStack.pop();
494  type = tag.getAttribute("type");
495  if (!type.length()) type = tag.getAttribute("rend");
496  }
497  if (type == "bold" || type == "b" || type == "x-b") {
498  outText("</b>", buf, u);
499  }
500  else if (type == "ol") {
501  outText("</span>", buf, u);
502  }
503  else if (type == "super") {
504  outText("</sup>", buf, u);
505  }
506  else if (type == "sub") {
507  outText("</sub>", buf, u);
508  }
509  else {
510  outText("</i>", buf, u);
511  }
512  }
513  }
514 
515  // <q> quote
516  // Rules for a quote element:
517  // If the tag is empty with an sID or an eID then use whatever it specifies for quoting.
518  // Note: empty elements without sID or eID are ignored.
519  // If the tag is <q> then use it's specifications and push it onto a stack for </q>
520  // If the tag is </q> then use the pushed <q> for specification
521  // If there is a marker attribute, possibly empty, this overrides osisQToTick.
522  // If osisQToTick, then output the marker, using level to determine the type of mark.
523  else if (!strcmp(tag.getName(), "q")) {
524  SWBuf type = tag.getAttribute("type");
525  SWBuf who = tag.getAttribute("who");
526  const char *tmp = tag.getAttribute("level");
527  int level = (tmp) ? atoi(tmp) : 1;
528  tmp = tag.getAttribute("marker");
529  bool hasMark = tmp;
530  SWBuf mark = tmp;
531 
532  // open <q> or <q sID... />
533  if ((!tag.isEmpty() && !tag.isEndTag()) || (tag.isEmpty() && tag.getAttribute("sID"))) {
534  // if <q> then remember it for the </q>
535  if (!tag.isEmpty()) {
536  u->tagStacks->quoteStack.push(tag.toString());
537  }
538 
539  // Do this first so quote marks are included as WoC
540  if (who == "Jesus")
541  outText(u->wordsOfChristStart, buf, u);
542 
543  // first check to see if we've been given an explicit mark
544  if (hasMark)
545  outText(mark, buf, u);
546  //alternate " and '
547  else if (u->osisQToTick)
548  outText((level % 2) ? '\"' : '\'', buf, u);
549  }
550  // close </q> or <q eID... />
551  else if ((tag.isEndTag()) || (tag.isEmpty() && tag.getAttribute("eID"))) {
552  // if it is </q> then pop the stack for the attributes
553  if (tag.isEndTag() && !u->tagStacks->quoteStack.empty()) {
554  XMLTag qTag(u->tagStacks->quoteStack.top());
555  u->tagStacks->quoteStack.pop();
556 
557  type = qTag.getAttribute("type");
558  who = qTag.getAttribute("who");
559  tmp = qTag.getAttribute("level");
560  level = (tmp) ? atoi(tmp) : 1;
561  tmp = qTag.getAttribute("marker");
562  hasMark = tmp;
563  mark = tmp;
564  }
565 
566  // first check to see if we've been given an explicit mark
567  if (hasMark)
568  outText(mark, buf, u);
569  // finally, alternate " and ', if config says we should supply a mark
570  else if (u->osisQToTick)
571  outText((level % 2) ? '\"' : '\'', buf, u);
572 
573  // Do this last so quote marks are included as WoC
574  if (who == "Jesus")
575  outText(u->wordsOfChristEnd, buf, u);
576  }
577  }
578 
579  // <transChange>
580  else if (!strcmp(tag.getName(), "transChange")) {
581  if ((!tag.isEndTag()) && (!tag.isEmpty())) {
582  SWBuf type = tag.getAttribute("type");
583  u->lastTransChange = type;
584 
585  // just do all transChange tags this way for now
586  if ((type == "added") || (type == "supplied"))
587  outText("<i>", buf, u);
588  else if (type == "tenseChange")
589  outText( "*", buf, u);
590  }
591  else if (tag.isEndTag()) {
592  SWBuf type = u->lastTransChange;
593  if ((type == "added") || (type == "supplied"))
594  outText("</i>", buf, u);
595  }
596  else { // empty transChange marker?
597  }
598  }
599 
600  // image
601  else if (!strcmp(tag.getName(), "figure")) {
602  const char *src = tag.getAttribute("src");
603  if (!src) // assert we have a src attribute
604  return false;
605 
606  SWBuf filepath;
607  if (userData->module) {
608  filepath = userData->module->getConfigEntry("AbsoluteDataPath");
609  if ((filepath.size()) && (filepath[filepath.size()-1] != '/') && (src[0] != '/'))
610  filepath += '/';
611  }
612  filepath += src;
613 
614  // images become clickable, if the UI supports showImage.
615  outText("<a href=\"passagestudy.jsp?action=showImage&value=", buf, u);
616  outText(URL::encode(filepath.c_str()).c_str(), buf, u);
617  outText("&module=", buf, u);
618  outText(URL::encode(u->version.c_str()).c_str(), buf, u);
619  outText("\">", buf, u);
620 
621  outText("<img src=\"file:", buf, u);
622  outText(filepath, buf, u);
623  outText("\" border=\"0\" />", buf, u);
624 
625  outText("</a>", buf, u);
626  }
627 
628  else {
629  return false; // we still didn't handle token
630  }
631  }
632  return true;
633 }
SWBuf & appendFormatted(const char *format,...)
Definition: swbuf.cpp:81
Definition: swbuf.h:47
unsigned long length() const
Definition: swbuf.h:197
virtual const char * getConfigEntry(const char *key) const
Definition: swmodule.cpp:1159
const SWModule * module
Definition: swbasicfilter.h:42
Definition: utilxml.h:38
bool renderNoteNumbers
Definition: osishtmlhref.h:36
bool substituteToken(SWBuf &buf, const char *token)
void processLemma(bool suspendTextPassThru, XMLTag &tag, SWBuf &buf)
char * getRawData()
Definition: swbuf.h:379
const char * c_str() const
Definition: swbuf.h:158
static void outText(const char *t, SWBuf &o, BasicFilterUserData *u)
void processMorph(bool suspendTextPassThru, XMLTag &tag, SWBuf &buf)
unsigned long size() const
Definition: swbuf.h:185
int size
Definition: regex.c:5043
SWBuf & toUpper()
Definition: swbuf.cpp:132
SWBuf & setFormatted(const char *format,...)
Definition: swbuf.cpp:50
static const SWBuf encode(const char *urlText)
Definition: url.cpp:231
SW_u32 getUniCharFromUTF8(const unsigned char **buf, bool skipValidation=false)
Definition: utilstr.h:88
void setSize(unsigned long len)
Definition: swbuf.h:255
bool SWBasicFilter::passAllowedEscapeString ( SWBuf buf,
const char *  escString 
)
protectedinherited

This passes allowed escapeStrings

Definition at line 223 of file swbasicfilter.cpp.

223  {
224  StringSet::iterator it;
225 
226  if (!escStringCaseSensitive) {
227  char *tmp = 0;
228  stdstr(&tmp, escString);
229  toupperstr(tmp);
230  it = p->escPassSet.find(tmp);
231  delete [] tmp;
232  } else
233  it = p->escPassSet.find(escString);
234 
235  if (it != p->escPassSet.end()) {
236  appendEscapeString(buf, escString);
237  return true;
238  }
239 
240  return false;
241 }
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
bool escStringCaseSensitive
Definition: swbasicfilter.h:74
char * toupperstr(char *t, unsigned int max=0)
Definition: stringmgr.h:107
Private * p
Definition: swbasicfilter.h:82
void appendEscapeString(SWBuf &buf, const char *escString)
virtual bool SWBasicFilter::processStage ( char  ,
SWBuf ,
char *&  ,
BasicFilterUserData  
)
inlineprotectedvirtualinherited

Reimplemented in OSISPlain.

Definition at line 185 of file swbasicfilter.h.

185 { return false; }
char SWBasicFilter::processText ( SWBuf text,
const SWKey key = 0,
const SWModule module = 0 
)
virtualinherited

This method processes and appropriately modifies the text given it for a particular filter task

Parameters
textThe text to be filtered/converted
keyCurrent key That was used.
moduleCurrent module.
Returns
0

Implements SWFilter.

Reimplemented in ThMLRTF, OSISOSIS, and OSISRTF.

Definition at line 315 of file swbasicfilter.cpp.

315  {
316  char *from;
317  char token[4096];
318  int tokpos = 0;
319  bool intoken = false;
320  bool inEsc = false;
321  int escStartPos = 0, escEndPos = 0;
322  int tokenStartPos = 0, tokenEndPos = 0;
323  SWBuf lastTextNode;
324  BasicFilterUserData *userData = createUserData(module, key);
325 
326  SWBuf orig = text;
327  from = orig.getRawData();
328  text = "";
329 
330  if (processStages & INITIALIZE) {
331  if (processStage(INITIALIZE, text, from, userData)) { // processStage handled it all
332  delete userData;
333  return 0;
334  }
335  }
336 
337  for (;*from; from++) {
338 
339  if (processStages & PRECHAR) {
340  if (processStage(PRECHAR, text, from, userData)) // processStage handled this char
341  continue;
342  }
343 
344  if (*from == tokenStart[tokenStartPos]) {
345  if (tokenStartPos == (tokenStartLen - 1)) {
346  intoken = true;
347  tokpos = 0;
348  token[0] = 0;
349  token[1] = 0;
350  token[2] = 0;
351  inEsc = false;
352  }
353  else tokenStartPos++;
354  continue;
355  }
356 
357  if (*from == escStart[escStartPos]) {
358  if (escStartPos == (escStartLen - 1)) {
359  intoken = true;
360  tokpos = 0;
361  token[0] = 0;
362  token[1] = 0;
363  token[2] = 0;
364  inEsc = true;
365  }
366  else escStartPos++;
367  continue;
368  }
369 
370  if (inEsc) {
371  if (*from == escEnd[escEndPos]) {
372  if (escEndPos == (escEndLen - 1)) {
373  intoken = inEsc = false;
374  userData->lastTextNode = lastTextNode;
375 
376  if (!userData->suspendTextPassThru) { //if text through is disabled no tokens should pass, too
377  if ((!handleEscapeString(text, token, userData)) && (passThruUnknownEsc)) {
378  appendEscapeString(text, token);
379  }
380  }
381  escEndPos = escStartPos = tokenEndPos = tokenStartPos = 0;
382  lastTextNode = "";
383  continue;
384  }
385  }
386  }
387 
388  if (!inEsc) {
389  if (*from == tokenEnd[tokenEndPos]) {
390  if (tokenEndPos == (tokenEndLen - 1)) {
391  intoken = false;
392  userData->lastTextNode = lastTextNode;
393  if ((!handleToken(text, token, userData)) && (passThruUnknownToken)) {
394  text += tokenStart;
395  text += token;
396  text += tokenEnd;
397  }
398  escEndPos = escStartPos = tokenEndPos = tokenStartPos = 0;
399  lastTextNode = "";
400  if (!userData->suspendTextPassThru) {
401  userData->lastSuspendSegment.size(0);
402  }
403  continue;
404  }
405  }
406  }
407 
408  if (intoken) {
409  if (tokpos < 4090) {
410  token[tokpos++] = *from;
411  token[tokpos+2] = 0;
412  }
413  }
414  else {
415  if ((!userData->supressAdjacentWhitespace) || (*from != ' ')) {
416  if (!userData->suspendTextPassThru) {
417  text.append(*from);
418  }
419  else userData->lastSuspendSegment.append(*from);
420  lastTextNode.append(*from);
421  }
422  userData->supressAdjacentWhitespace = false;
423  }
424 
425  if (processStages & POSTCHAR)
426  processStage(POSTCHAR, text, from, userData);
427 
428  }
429 
430  if (processStages & FINALIZE)
431  processStage(FINALIZE, text, from, userData);
432 
433  delete userData;
434  return 0;
435 }
static const char PRECHAR
Definition: swbasicfilter.h:97
Definition: swbuf.h:47
static const char POSTCHAR
Definition: swbasicfilter.h:98
char * tokenStart
Definition: swbasicfilter.h:64
virtual bool handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData)
bool passThruUnknownEsc
Definition: swbasicfilter.h:77
virtual bool handleEscapeString(SWBuf &buf, const char *escString, BasicFilterUserData *userData)
bool passThruUnknownToken
Definition: swbasicfilter.h:76
static const char FINALIZE
Definition: swbasicfilter.h:99
char * getRawData()
Definition: swbuf.h:379
SWBuf & append(const char *str, long max=-1)
Definition: swbuf.h:274
virtual bool processStage(char, SWBuf &, char *&, BasicFilterUserData *)
virtual BasicFilterUserData * createUserData(const SWModule *module, const SWKey *key)
Definition: swbasicfilter.h:91
unsigned long size() const
Definition: swbuf.h:185
static const char INITIALIZE
Definition: swbasicfilter.h:96
void appendEscapeString(SWBuf &buf, const char *escString)
void SWBasicFilter::removeAllowedEscapeString ( const char *  findString)
protectedinherited

Unregisters an esc control sequence that can pass unchanged

Definition at line 169 of file swbasicfilter.cpp.

169  {
170  if (p->escPassSet.find(findString) != p->escPassSet.end()) {
171  p->escPassSet.erase( p->escPassSet.find(findString) );
172  }
173 }
Private * p
Definition: swbasicfilter.h:82
void SWBasicFilter::removeEscapeStringSubstitute ( const char *  findString)
protectedinherited

Unregisters an esc control sequence

Definition at line 189 of file swbasicfilter.cpp.

189  {
190  if (p->escSubMap.find(findString) != p->escSubMap.end()) {
191  p->escSubMap.erase( p->escSubMap.find(findString) );
192  }
193 }
Private * p
Definition: swbasicfilter.h:82
void SWBasicFilter::removeTokenSubstitute ( const char *  findString)
protectedinherited

Unregisters a simple token substitute

Definition at line 149 of file swbasicfilter.cpp.

149  {
150  if (p->tokenSubMap.find(findString) != p->tokenSubMap.end()) {
151  p->tokenSubMap.erase( p->tokenSubMap.find(findString) );
152  }
153 }
DualStringMap tokenSubMap
Private * p
Definition: swbasicfilter.h:82
void SWBasicFilter::setEscapeEnd ( const char *  escEnd)
protectedinherited

Sets the end of escape sequence (by default ";").

Definition at line 297 of file swbasicfilter.cpp.

297  {
298  stdstr(&(this->escEnd), escEnd);
299  escEndLen = strlen(escEnd);
300 }
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
void SWBasicFilter::setEscapeStart ( const char *  escStart)
protectedinherited

Sets the beginning of escape sequence (by default "&").

Definition at line 291 of file swbasicfilter.cpp.

291  {
292  stdstr(&(this->escStart), escStart);
293  escStartLen = strlen(escStart);
294 }
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
void SWBasicFilter::setEscapeStringCaseSensitive ( bool  val)
protectedinherited

Are escapeStrings case sensitive or not? Call this function before addEscapeStingSubstitute()

Definition at line 131 of file swbasicfilter.cpp.

131  {
133 }
bool escStringCaseSensitive
Definition: swbasicfilter.h:74
void OSISHTMLHREF::setMorphFirst ( bool  val = true)
inline

Definition at line 64 of file osishtmlhref.h.

64 { morphFirst = val; }
void SWBasicFilter::setPassThruNumericEscapeString ( bool  val)
protectedinherited

Sets whether to pass thru a numeric escape sequence unchanged or allow it to be handled otherwise. Default is false.

Definition at line 121 of file swbasicfilter.cpp.

121  {
122  passThruUnknownEsc = val;
123 }
bool passThruUnknownEsc
Definition: swbasicfilter.h:77
void SWBasicFilter::setPassThruUnknownEscapeString ( bool  val)
protectedinherited

Sets whether to pass thru an unknown escape sequence unchanged or just remove it. Default is false.

Definition at line 116 of file swbasicfilter.cpp.

116  {
117  passThruUnknownEsc = val;
118 }
bool passThruUnknownEsc
Definition: swbasicfilter.h:77
void SWBasicFilter::setPassThruUnknownToken ( bool  val)
protectedinherited

Sets whether to pass thru an unknown token unchanged or just remove it. Default is false.

Definition at line 111 of file swbasicfilter.cpp.

111  {
112  passThruUnknownToken = val;
113 }
bool passThruUnknownToken
Definition: swbasicfilter.h:76
void OSISHTMLHREF::setRenderNoteNumbers ( bool  val = true)
inline

Definition at line 65 of file osishtmlhref.h.

65 { renderNoteNumbers = val; }
bool renderNoteNumbers
Definition: osishtmlhref.h:36
virtual void SWBasicFilter::setStageProcessing ( char  stages)
inlineprotectedvirtualinherited

Definition at line 186 of file swbasicfilter.h.

186 { processStages = stages; } // see STATICs up above
void SWBasicFilter::setTokenCaseSensitive ( bool  val)
protectedinherited

Are tokens case sensitive (like in GBF) or not? Call this function before addTokenSubstitute()

Definition at line 126 of file swbasicfilter.cpp.

126  {
127  tokenCaseSensitive = val;
128 }
bool tokenCaseSensitive
Definition: swbasicfilter.h:75
void SWBasicFilter::setTokenEnd ( const char *  tokenEnd)
protectedinherited

Sets the end of token start sequence (by default ">").

Definition at line 309 of file swbasicfilter.cpp.

309  {
310  stdstr(&(this->tokenEnd), tokenEnd);
311  tokenEndLen = strlen(tokenEnd);
312 }
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
void SWBasicFilter::setTokenStart ( const char *  tokenStart)
protectedinherited

Sets the beginning of token start sequence (by default "<").

Definition at line 303 of file swbasicfilter.cpp.

303  {
304  stdstr(&(this->tokenStart), tokenStart);
305  tokenStartLen = strlen(tokenStart);
306 }
char * tokenStart
Definition: swbasicfilter.h:64
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
bool SWBasicFilter::substituteEscapeString ( SWBuf buf,
const char *  escString 
)
protectedinherited

This function performs the substitution of escapeStrings

Definition at line 253 of file swbasicfilter.cpp.

253  {
254  DualStringMap::iterator it;
255 
256  if (*escString == '#') {
257  return handleNumericEscapeString(buf, escString);
258  }
259 
260  if (passAllowedEscapeString(buf, escString)) {
261  return true;
262  }
263 
264  if (!escStringCaseSensitive) {
265  char *tmp = 0;
266  stdstr(&tmp, escString);
267  toupperstr(tmp);
268  it = p->escSubMap.find(tmp);
269  delete [] tmp;
270  } else
271  it = p->escSubMap.find(escString);
272 
273  if (it != p->escSubMap.end()) {
274  buf += it->second.c_str();
275  return true;
276  }
277  return false;
278 }
virtual bool handleNumericEscapeString(SWBuf &buf, const char *escString)
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
const char * c_str() const
Definition: swbuf.h:158
bool escStringCaseSensitive
Definition: swbasicfilter.h:74
bool passAllowedEscapeString(SWBuf &buf, const char *escString)
char * toupperstr(char *t, unsigned int max=0)
Definition: stringmgr.h:107
Private * p
Definition: swbasicfilter.h:82
bool SWBasicFilter::substituteToken ( SWBuf buf,
const char *  token 
)
protectedinherited

This function performs the substitution of tokens

Definition at line 196 of file swbasicfilter.cpp.

196  {
197  DualStringMap::iterator it;
198 
199  if (!tokenCaseSensitive) {
200  char *tmp = 0;
201  stdstr(&tmp, token);
202  toupperstr(tmp);
203  it = p->tokenSubMap.find(tmp);
204  delete [] tmp;
205  } else
206  it = p->tokenSubMap.find(token);
207 
208  if (it != p->tokenSubMap.end()) {
209  buf += it->second.c_str();
210  return true;
211  }
212  return false;
213 }
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
const char * c_str() const
Definition: swbuf.h:158
bool tokenCaseSensitive
Definition: swbasicfilter.h:75
DualStringMap tokenSubMap
char * toupperstr(char *t, unsigned int max=0)
Definition: stringmgr.h:107
Private * p
Definition: swbasicfilter.h:82

Member Data Documentation

const char SWBasicFilter::FINALIZE = 8
staticprotectedinherited

Definition at line 99 of file swbasicfilter.h.

const char SWBasicFilter::INITIALIZE = 1
staticprotectedinherited

Definition at line 96 of file swbasicfilter.h.

bool OSISHTMLHREF::morphFirst
private

Definition at line 35 of file osishtmlhref.h.

const char SWBasicFilter::POSTCHAR = 4
staticprotectedinherited

Definition at line 98 of file swbasicfilter.h.

const char SWBasicFilter::PRECHAR = 2
staticprotectedinherited

Definition at line 97 of file swbasicfilter.h.

bool OSISHTMLHREF::renderNoteNumbers
private

Definition at line 36 of file osishtmlhref.h.


The documentation for this class was generated from the following files: