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

#include <osiswordjs.h>

+ Inheritance diagram for OSISWordJS:
+ Collaboration diagram for OSISWordJS:

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 ()
 
 OSISWordJS ()
 
virtual char processText (SWBuf &text, const SWKey *key=0, const SWModule *module=0)
 
void setDefaultModules (SWModule *defaultGreekLex=0, SWModule *defaultHebLex=0, SWModule *defaultGreekParse=0, SWModule *defaultHebParse=0)
 
void setMgr (SWMgr *mgr)
 
virtual void setOptionValue (const char *ival)
 
virtual ~OSISWordJS ()
 

Protected Attributes

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

Private Attributes

SWModuledefaultGreekLex
 
SWModuledefaultGreekParse
 
SWModuledefaultHebLex
 
SWModuledefaultHebParse
 
SWMgrmgr
 

Detailed Description

This Filter inject JavaScript proving onclick events for modules marked up in OSIS

Definition at line 36 of file osiswordjs.h.

Constructor & Destructor Documentation

OSISWordJS::OSISWordJS ( )

Definition at line 49 of file osiswordjs.cpp.

50 
51  defaultGreekLex = 0;
52  defaultHebLex = 0;
54  defaultHebParse = 0;
55  mgr = 0;
56 }
SWModule * defaultHebParse
Definition: osiswordjs.h:40
SWModule * defaultHebLex
Definition: osiswordjs.h:38
static const StringList * oValues()
SWModule * defaultGreekParse
Definition: osiswordjs.h:39
static const char oName[]
static const char oTip[]
SWModule * defaultGreekLex
Definition: osiswordjs.h:37
SWMgr * mgr
Definition: osiswordjs.h:41
OSISWordJS::~OSISWordJS ( )
virtual

Definition at line 59 of file osiswordjs.cpp.

59  {
60 }

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 OSISWordJS::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 63 of file osiswordjs.cpp.

63  {
64  if (option) {
65  char token[2112]; // cheese. Fix.
66  int tokpos = 0;
67  bool intoken = false;
68  int wordNum = 1;
69  char wordstr[11];
70  SWBuf modName = (module)?module->getName():"";
71  // add TR to w src in KJV then remove this next line
72  SWBuf wordSrcPrefix = (modName == "KJV")?SWBuf("TR"):modName;
73 
74  const VerseKey *vkey = 0;
75  if (key) {
76  vkey = SWDYNAMIC_CAST(const VerseKey, key);
77  }
78 
79  const SWBuf orig = text;
80  const char * from = orig.c_str();
81 
82  for (text = ""; *from; ++from) {
83  if (*from == '<') {
84  intoken = true;
85  tokpos = 0;
86  token[0] = 0;
87  token[1] = 0;
88  token[2] = 0;
89  continue;
90  }
91  if (*from == '>') { // process tokens
92  intoken = false;
93  if ((*token == 'w') && (token[1] == ' ')) { // Word
94  XMLTag wtag(token);
95  sprintf(wordstr, "%03d", wordNum);
96  SWBuf lemmaClass;
97  SWBuf lemma;
98  SWBuf morph;
99  SWBuf page;
100  SWBuf src;
101  char gh = 0;
102  page = module->getEntryAttributes()["Word"][wordstr]["Page"].c_str();
103  if (page.length()) page = (SWBuf)"p:" + page;
104  int count = atoi(module->getEntryAttributes()["Word"][wordstr]["PartCount"].c_str());
105  for (int i = 0; i < count; i++) {
106 
107  // for now, lemma class can just be equal to last lemma class in multi part word
108  SWBuf tmp = "LemmaClass";
109  if (count > 1) tmp.appendFormatted(".%d", i+1);
110  lemmaClass = module->getEntryAttributes()["Word"][wordstr][tmp];
111 
112  tmp = "Lemma";
113  if (count > 1) tmp.appendFormatted(".%d", i+1);
114  tmp = (module->getEntryAttributes()["Word"][wordstr][tmp].c_str());
115 
116  // if we're strongs,
117  if (lemmaClass == "strong") {
118  gh = tmp[0];
119  tmp << 1;
120  }
121  if (lemma.size()) lemma += "|";
122  lemma += tmp;
123 
124  tmp = "Morph";
125  if (count > 1) tmp.appendFormatted(".%d", i+1);
126  tmp = (module->getEntryAttributes()["Word"][wordstr][tmp].c_str());
127  if (morph.size()) morph += "|";
128  morph += tmp;
129 
130  tmp = "Src";
131  if (count > 1) tmp.appendFormatted(".%d", i+1);
132  tmp = (module->getEntryAttributes()["Word"][wordstr][tmp].c_str());
133  if (!tmp.length()) tmp.appendFormatted("%d", wordNum);
134  tmp.insert(0, wordSrcPrefix);
135  if (src.size()) src += "|";
136  src += tmp;
137  }
138 
139  SWBuf lexName = "";
140  // we can pass the real lex name in, but we have some
141  // aliases in the javascript to optimize bandwidth
142  if ((gh == 'G') && (defaultGreekLex)) {
143  lexName = (!strcmp(defaultGreekLex->getName(), "StrongsGreek"))?"G":defaultGreekLex->getName();
144  }
145  else if ((gh == 'H') && (defaultHebLex)) {
146  lexName = (!strcmp(defaultHebLex->getName(), "StrongsHebrew"))?"H":defaultHebLex->getName();
147  }
148 
149  SWBuf xlit = wtag.getAttribute("xlit");
150 
151  if ((lemmaClass != "strong") && (xlit.startsWith("betacode:"))) {
152  lexName = "betacode";
153 // const char *m = strchr(xlit.c_str(), ':');
154 // strong = ++m;
155  }
156  SWBuf wordID;
157  if (vkey) {
158  // optimize for bandwidth and use only the verse as the unique entry id
159  wordID.appendFormatted("%d", vkey->getVerse());
160  }
161  else {
162  wordID = key->getText();
163  }
164  wordID.appendFormatted("_%s", src.c_str());
165  // clean up our word ID for XHTML
166  for (unsigned int i = 0; i < wordID.size(); i++) {
167  if ((!isdigit(wordID[i])) && (!isalpha(wordID[i]))) {
168  wordID[i] = '_';
169  }
170  }
171  // 'p' = 'fillpop' to save bandwidth
172  text.appendFormatted("<span class=\"clk\" onclick=\"p('%s','%s','%s','%s','%s','%s');\" >", lexName.c_str(), lemma.c_str(), wordID.c_str(), morph.c_str(), page.c_str(), modName.c_str());
173  wordNum++;
174 
175  if (wtag.isEmpty()) {
176  text += "</w></span>";
177  }
178  }
179  if ((*token == '/') && (token[1] == 'w') && option) { // Word
180  text += "</w></span>";
181  continue;
182  }
183 
184  // if not a strongs token, keep token in text
185  text.append('<');
186  text.append(token);
187  text.append('>');
188 
189  continue;
190  }
191  if (intoken) {
192  if (tokpos < 2045) {
193  token[tokpos++] = *from;
194  token[tokpos+2] = 0;
195  }
196  }
197  else {
198  text.append(*from);
199  }
200  }
201  }
202  return 0;
203 }
const char * getName() const
Definition: swmodule.cpp:204
int page
Definition: imp2vs.cpp:303
SWBuf & appendFormatted(const char *format,...)
Definition: swbuf.cpp:81
Definition: swbuf.h:47
unsigned long length() const
Definition: swbuf.h:197
SWText * module
Definition: osis2mod.cpp:105
Definition: utilxml.h:38
bool startsWith(const SWBuf &prefix) const
Definition: swbuf.h:486
SWModule * defaultHebLex
Definition: osiswordjs.h:38
virtual const char * getText() const
Definition: swkey.cpp:184
void insert(unsigned long pos, const char *str, unsigned long start=0, signed long max=-1)
Definition: swbuf.cpp:99
const char * c_str() const
Definition: swbuf.h:158
SWBuf & append(const char *str, long max=-1)
Definition: swbuf.h:274
virtual int getVerse() const
Definition: versekey.cpp:1534
#define SWDYNAMIC_CAST(className, object)
Definition: defs.h:47
unsigned long size() const
Definition: swbuf.h:185
virtual AttributeTypeList & getEntryAttributes() const
Definition: swmodule.h:817
SWModule * defaultGreekLex
Definition: osiswordjs.h:37
void OSISWordJS::setDefaultModules ( SWModule defaultGreekLex = 0,
SWModule defaultHebLex = 0,
SWModule defaultGreekParse = 0,
SWModule defaultHebParse = 0 
)
inline

Definition at line 47 of file osiswordjs.h.

47  {
48  this->defaultGreekLex = defaultGreekLex;
49  this->defaultHebLex = defaultHebLex;
50  this->defaultGreekParse = defaultGreekParse;
51  this->defaultHebParse = defaultHebParse;
52  }
SWModule * defaultHebParse
Definition: osiswordjs.h:40
SWModule * defaultHebLex
Definition: osiswordjs.h:38
SWModule * defaultGreekParse
Definition: osiswordjs.h:39
SWModule * defaultGreekLex
Definition: osiswordjs.h:37
void OSISWordJS::setMgr ( SWMgr mgr)
inline

Definition at line 53 of file osiswordjs.h.

53 { this->mgr = mgr; }
SWMgr * mgr
Definition: osiswordjs.h:41
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

SWModule* OSISWordJS::defaultGreekLex
private

Definition at line 37 of file osiswordjs.h.

SWModule* OSISWordJS::defaultGreekParse
private

Definition at line 39 of file osiswordjs.h.

SWModule* OSISWordJS::defaultHebLex
private

Definition at line 38 of file osiswordjs.h.

SWModule* OSISWordJS::defaultHebParse
private

Definition at line 40 of file osiswordjs.h.

bool SWOptionFilter::isBooleanVal
protectedinherited

Definition at line 55 of file swoptfilter.h.

SWMgr* OSISWordJS::mgr
private

Definition at line 41 of file osiswordjs.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: