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

#include <thmlscripref.h>

+ Inheritance diagram for ThMLScripref:
+ Collaboration diagram for ThMLScripref:

Public Member Functions

virtual const char * getHeader () const
 
virtual const char * getOptionName ()
 
virtual const char * getOptionTip ()
 
virtual const char * getOptionValue ()
 
virtual StringList getOptionValues ()
 
bool isBoolean ()
 
virtual char processText (SWBuf &text, const SWKey *key=0, const SWModule *module=0)
 
virtual void setOptionValue (const char *ival)
 
 ThMLScripref ()
 
virtual ~ThMLScripref ()
 

Protected Attributes

bool isBooleanVal
 
bool option
 
SWBuf optionValue
 
const char * optName
 
const char * optTip
 
const StringListoptValues
 

Detailed Description

This Filter shows/hides scripture references in a ThML text

Definition at line 33 of file thmlscripref.h.

Constructor & Destructor Documentation

ThMLScripref::ThMLScripref ( )

Definition at line 47 of file thmlscripref.cpp.

48 }
static const StringList * oValues()
static const char oName[]
static const char oTip[]
ThMLScripref::~ThMLScripref ( )
virtual

Definition at line 51 of file thmlscripref.cpp.

51  {
52 }

Member Function Documentation

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 ""; }
virtual const char* SWOptionFilter::getOptionName ( )
inlinevirtualinherited

gets the name of the option of this filter

Returns
option name

Reimplemented in UTF8Transliterator.

Definition at line 72 of file swoptfilter.h.

72 { return optName; }
const char * optName
Definition: swoptfilter.h:51
virtual const char* SWOptionFilter::getOptionTip ( )
inlinevirtualinherited

gets a short explanation of the option of this filter; it could be presented to the user in frontend programs

Returns
option tip/explanation

Reimplemented in UTF8Transliterator.

Definition at line 78 of file swoptfilter.h.

78 { return optTip; }
const char * optTip
Definition: swoptfilter.h:52
const char * SWOptionFilter::getOptionValue ( )
virtualinherited
Returns
The value of the current option.

Reimplemented in UTF8Transliterator.

Definition at line 62 of file swoptfilter.cpp.

62  {
63  return optionValue;
64 }
SWBuf optionValue
Definition: swoptfilter.h:50
virtual StringList SWOptionFilter::getOptionValues ( )
inlinevirtualinherited

returns a list of the possible option values

Returns
list of option values

Reimplemented in UTF8Transliterator.

Definition at line 84 of file swoptfilter.h.

84 { return *optValues; }
const StringList * optValues
Definition: swoptfilter.h:53
bool SWOptionFilter::isBoolean ( )
inlineinherited

many options are simple Off/On boolean type, and frontends may wish to show these with checkmarks or the like to the end user. This is a convenience method to allow a frontend to check if this filter has only Off/On values

Definition at line 67 of file swoptfilter.h.

67 { return isBooleanVal; }
char ThMLScripref::processText ( SWBuf text,
const SWKey key = 0,
const SWModule module = 0 
)
virtual

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.

Definition at line 55 of file thmlscripref.cpp.

55  {
56  SWBuf token;
57  bool intoken = false;
58  bool hide = false;
59  SWBuf tagText;
60  XMLTag startTag;
61  SWBuf refs = "";
62  int footnoteNum = 1;
63  char buf[254];
64  SWKey *p = (module) ? module->createKey() : (key) ? key->clone() : new VerseKey();
65  VerseKey *parser = SWDYNAMIC_CAST(VerseKey, p);
66  if (!parser) {
67  delete p;
68  parser = new VerseKey();
69  }
70  *parser = key->getText();
71 
72  SWBuf orig = text;
73  const char *from = orig.c_str();
74 
75  for (text = ""; *from; from++) {
76  if (*from == '<') {
77  intoken = true;
78  token = "";
79  continue;
80  }
81  if (*from == '>') { // process tokens
82  intoken = false;
83 
84  XMLTag tag(token);
85  if (!strcmp(tag.getName(), "scripRef")) {
86  if (!tag.isEndTag()) {
87  if (!tag.isEmpty()) {
88  refs = "";
89  startTag = tag;
90  hide = true;
91  tagText = "";
92  continue;
93  }
94  }
95  if (hide && tag.isEndTag()) {
96  if (module->isProcessEntryAttributes()) {
97  SWBuf fc = module->getEntryAttributes()["Footnote"]["count"]["value"];
98  footnoteNum = (fc.length()) ? atoi(fc.c_str()) : 0;
99  sprintf(buf, "%i", ++footnoteNum);
100  module->getEntryAttributes()["Footnote"]["count"]["value"] = buf;
101  StringList attributes = startTag.getAttributeNames();
102  for (StringList::iterator it = attributes.begin(); it != attributes.end(); it++) {
103  module->getEntryAttributes()["Footnote"][buf][it->c_str()] = startTag.getAttribute(it->c_str());
104  }
105  module->getEntryAttributes()["Footnote"][buf]["body"] = tagText;
106  startTag.setAttribute("swordFootnote", buf);
107  SWBuf passage = startTag.getAttribute("passage");
108  if (passage.length())
109  refs = parser->parseVerseList(passage.c_str(), *parser, true).getRangeText();
110  else refs = parser->parseVerseList(tagText.c_str(), *parser, true).getRangeText();
111  module->getEntryAttributes()["Footnote"][buf]["refList"] = refs.c_str();
112  }
113  hide = false;
114  if (option) { // we want the tag in the text
115  text += startTag;
116  text.append(tagText);
117  }
118  else continue;
119  }
120  }
121 
122  // if not a scripRef token, keep token in text
123  if ((!strcmp(tag.getName(), "scripRef")) && (!tag.isEndTag())) {
124  SWBuf osisRef = tag.getAttribute("passage");
125  if (refs.length())
126  refs += "; ";
127  refs += osisRef;
128  }
129  if (!hide) {
130  text += '<';
131  text.append(token);
132  text += '>';
133  }
134  else {
135  tagText += '<';
136  tagText.append(token);
137  tagText += '>';
138  }
139  continue;
140  }
141  if (intoken) { //copy token
142  token += *from;
143  }
144  else if (!hide) { //copy text which is not inside a token
145  text += *from;
146  }
147  else tagText += *from;
148  }
149  delete parser;
150  return 0;
151 }
Definition: swbuf.h:47
unsigned long length() const
Definition: swbuf.h:197
const char * setAttribute(const char *attribName, const char *attribValue, int partNum=-1, char partSplit= '|')
Definition: utilxml.cpp:248
SWText * module
Definition: osis2mod.cpp:105
Definition: utilxml.h:38
virtual SWKey * clone() const
Definition: swkey.cpp:75
virtual const char * getText() const
Definition: swkey.cpp:184
const StringList getAttributeNames() const
Definition: utilxml.cpp:188
const char * c_str() const
Definition: swbuf.h:158
std::list< SWBuf > StringList
Definition: swmodule.cpp:91
SWBuf & append(const char *str, long max=-1)
Definition: swbuf.h:274
virtual ListKey parseVerseList(const char *buf, const char *defaultKey=0, bool expandRange=false, bool useChapterAsVerse=false)
Definition: versekey.cpp:515
#define SWDYNAMIC_CAST(className, object)
Definition: defs.h:47
virtual bool isProcessEntryAttributes() const
Definition: swmodule.h:832
virtual AttributeTypeList & getEntryAttributes() const
Definition: swmodule.h:817
const char * getAttribute(const char *attribName, int partNum=-1, char partSplit= '|') const
Definition: utilxml.cpp:230
virtual SWKey * createKey() const
Definition: swmodule.cpp:173
Definition: swkey.h:77
void SWOptionFilter::setOptionValue ( const char *  ival)
virtualinherited

sets the value of the option of this filter, e.g maybe a strong's filter might be set to "On" / "Off" - that would mean to show or not to show the strongs in the text, see also getOptionValues()

Parameters
ivalthe new option value

Reimplemented in UTF8Transliterator.

Definition at line 52 of file swoptfilter.cpp.

52  {
53  for (StringList::const_iterator loop = optValues->begin(); loop != optValues->end(); loop++) {
54  if (!stricmp(loop->c_str(), ival)) {
55  optionValue = *loop;
56  option = (!strnicmp(ival, "On", 2)); // convenience for boolean filters
57  break;
58  }
59  }
60 }
int stricmp(const char *s1, const char *s2)
Definition: utilstr.cpp:194
SWBuf optionValue
Definition: swoptfilter.h:50
int strnicmp(const char *s1, const char *s2, int len)
Definition: utilstr.cpp:180
const StringList * optValues
Definition: swoptfilter.h:53

Member Data Documentation

bool SWOptionFilter::isBooleanVal
protectedinherited

Definition at line 55 of file swoptfilter.h.

bool SWOptionFilter::option
protectedinherited

Definition at line 54 of file swoptfilter.h.

SWBuf SWOptionFilter::optionValue
protectedinherited

Definition at line 50 of file swoptfilter.h.

const char* SWOptionFilter::optName
protectedinherited

Definition at line 51 of file swoptfilter.h.

const char* SWOptionFilter::optTip
protectedinherited

Definition at line 52 of file swoptfilter.h.

const StringList* SWOptionFilter::optValues
protectedinherited

Definition at line 53 of file swoptfilter.h.


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