The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
osiswebif.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * osiswebif.cpp - OSIS to HTML filter with hrefs for strongs and
4  * morph tags
5  *
6  * $Id: osiswebif.cpp 3648 2019-06-11 01:39:52Z scribe $
7  *
8  * Copyright 2003-2013 CrossWire Bible Society (http://www.crosswire.org)
9  * CrossWire Bible Society
10  * P. O. Box 2528
11  * Tempe, AZ 85280-2528
12  *
13  * This program is free software; you can redistribute it and/or modify it
14  * under the terms of the GNU General Public License as published by the
15  * Free Software Foundation version 2.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * General Public License for more details.
21  *
22  */
23 
24 #include <stdlib.h>
25 #include <osiswebif.h>
26 #include <utilxml.h>
27 #include <url.h>
28 #include <versekey.h>
29 #include <swmodule.h>
30 #include <ctype.h>
31 
32 
34 
35 
36 OSISWEBIF::OSISWEBIF() : baseURL(""), passageStudyURL(baseURL + "passagestudy.jsp"), javascript(false) {
37 }
38 
39 
41  MyUserData *u = (MyUserData *)OSISXHTML::createUserData(module, key);
42  u->interModuleLinkStart = "<a href=\"#\" onclick=\"return im('%s', '%s');\">";
43  u->interModuleLinkEnd = "</a>";
44  if (module) u->fn = module->getConfigEntry("EmbeddedFootnoteMarkers");
45  return u;
46 }
47 
48 bool OSISWEBIF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) {
49  MyUserData *u = (MyUserData *)userData;
50  SWBuf scratch;
51  bool sub = (u->suspendTextPassThru) ? substituteToken(scratch, token) : substituteToken(buf, token);
52  if (!sub) {
53 
54  // manually process if it wasn't a simple substitution
55  XMLTag tag(token);
56 
57  // <w> tag
58  if (!strcmp(tag.getName(), "w")) {
59 
60  // start <w> tag
61  if ((!tag.isEmpty()) && (!tag.isEndTag())) {
62  u->w = token;
63  }
64 
65  // end or empty <w> tag
66  else {
67  bool endTag = tag.isEndTag();
68  SWBuf lastText;
69  bool show = true; // to handle unplaced article in kjv2003-- temporary till combined
70 
71  if (endTag) {
72  tag = u->w.c_str();
73  lastText = u->lastTextNode.c_str();
74  }
75  else lastText = "stuff";
76 
77  const char *attrib;
78  const char *val;
79  if ((attrib = tag.getAttribute("xlit"))) {
80  val = strchr(attrib, ':');
81  val = (val) ? (val + 1) : attrib;
82 // buf.appendFormatted(" %s", val);
83  }
84  if ((attrib = tag.getAttribute("gloss"))) {
85  val = strchr(attrib, ':');
86  val = (val) ? (val + 1) : attrib;
87 // buf.appendFormatted(" %s", val);
88  }
89  if ((attrib = tag.getAttribute("lemma"))) {
90  int count = tag.getAttributePartCount("lemma", ' ');
91  int i = (count > 1) ? 0 : -1; // -1 for whole value cuz it's faster, but does the same thing as 0
92  do {
93  attrib = tag.getAttribute("lemma", i, ' ');
94  if (i < 0) i = 0; // to handle our -1 condition
95  val = strchr(attrib, ':');
96  val = (val) ? (val + 1) : attrib;
97  const char *val2 = val;
98  if ((strchr("GH", *val)) && (isdigit(val[1])))
99  val2++;
100  if ((!strcmp(val2, "3588")) && (lastText.length() < 1))
101  show = false;
102  else buf.appendFormatted(" <small><em>&lt;<a href=\"%s?showStrong=%s#cv\">%s</a>&gt;</em></small> ", passageStudyURL.c_str(), URL::encode(val2).c_str(), val2);
103  } while (++i < count);
104  }
105  if ((attrib = tag.getAttribute("morph")) && (show)) {
106  SWBuf savelemma = tag.getAttribute("savlm");
107  if ((strstr(savelemma.c_str(), "3588")) && (lastText.length() < 1))
108  show = false;
109  if (show) {
110  int count = tag.getAttributePartCount("morph", ' ');
111  int i = (count > 1) ? 0 : -1; // -1 for whole value cuz it's faster, but does the same thing as 0
112  do {
113  attrib = tag.getAttribute("morph", i, ' ');
114  if (i < 0) i = 0; // to handle our -1 condition
115  val = strchr(attrib, ':');
116  val = (val) ? (val + 1) : attrib;
117  const char *val2 = val;
118  if ((*val == 'T') && (strchr("GH", val[1])) && (isdigit(val[2])))
119  val2+=2;
120  buf.appendFormatted(" <small><em>(<a href=\"%s?showMorph=%s#cv\">%s</a>)</em></small> ", passageStudyURL.c_str(), URL::encode(val2).c_str(), val2);
121  } while (++i < count);
122  }
123  }
124  if ((attrib = tag.getAttribute("POS"))) {
125  val = strchr(attrib, ':');
126  val = (val) ? (val + 1) : attrib;
127  buf.appendFormatted(" %s", val);
128  }
129 
130  /*if (endTag)
131  buf += "}";*/
132  }
133  }
134 
135  // <note> tag
136  else if (!strcmp(tag.getName(), "note")) {
137  if (!tag.isEndTag()) {
138  SWBuf type = tag.getAttribute("type");
139  bool strongsMarkup = (type == "x-strongsMarkup" || type == "strongsMarkup"); // the latter is deprecated
140  if (strongsMarkup) {
141  tag.setEmpty(false); // handle bug in KJV2003 module where some note open tags were <note ... />
142  }
143 
144  if (!tag.isEmpty()) {
145  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
146  SWBuf footnoteNumber = tag.getAttribute("swordFootnote");
147  SWBuf n = tag.getAttribute("n");
148  SWBuf modName = (u->module) ? u->module->getName() : "";
149  if (u->vkey) {
150  char ch = ((tag.getAttribute("type") && ((!strcmp(tag.getAttribute("type"), "crossReference")) || (!strcmp(tag.getAttribute("type"), "x-cross-ref")))) ? 'x':'n');
151  buf.append("<span");
152  if (n.length()) buf.appendFormatted(" data-n=\"%s\"", n.c_str());
153  else if (u->fn != "true") buf.appendFormatted(" data-n=\"%c\"", ch);
154  buf.appendFormatted(" class=\"fn\" onclick=\"f(\'%s\',\'%s\',\'%s\');\" >%c</span>", modName.c_str(), u->key->getText(), footnoteNumber.c_str(), ch);
155  }
156  }
157  u->suspendTextPassThru = (++u->suspendLevel);
158  }
159  }
160  if (tag.isEndTag()) {
161  u->suspendTextPassThru = (--u->suspendLevel);
162 
163  }
164  }
165 
166 
167  // handled appropriately in base class
168  else {
169  return OSISXHTML::handleToken(buf, token, userData);
170  }
171  }
172  return true;
173 }
174 
175 
177 
const char * getName() const
Definition: swmodule.cpp:204
SWBuf interModuleLinkStart
Definition: osisxhtml.h:54
#define SWORD_NAMESPACE_START
Definition: defs.h:39
SWBuf & appendFormatted(const char *format,...)
Definition: swbuf.cpp:81
const SWBuf passageStudyURL
Definition: osiswebif.h:35
Definition: swbuf.h:47
unsigned long length() const
Definition: swbuf.h:197
void setEmpty(bool value)
Definition: utilxml.h:66
virtual const char * getConfigEntry(const char *key) const
Definition: swmodule.cpp:1159
const SWModule * module
Definition: swbasicfilter.h:42
const char * getName() const
Definition: utilxml.h:58
SWText * module
Definition: osis2mod.cpp:105
Definition: utilxml.h:38
bool isEmpty() const
Definition: utilxml.h:60
bool substituteToken(SWBuf &buf, const char *token)
const VerseKey * vkey
Definition: swbasicfilter.h:44
virtual BasicFilterUserData * createUserData(const SWModule *module, const SWKey *key)
Definition: osiswebif.cpp:40
virtual const char * getText() const
Definition: swkey.cpp:184
const char * c_str() const
Definition: swbuf.h:158
SWBuf & append(const char *str, long max=-1)
Definition: swbuf.h:274
#define false
Definition: regex.c:407
const SWKey * key
Definition: swbasicfilter.h:43
const char * getAttribute(const char *attribName, int partNum=-1, char partSplit= '|') const
Definition: utilxml.cpp:230
bool isEndTag(const char *eID=0) const
Definition: utilxml.cpp:323
virtual BasicFilterUserData * createUserData(const SWModule *module, const SWKey *key)
Definition: osisxhtml.cpp:147
virtual bool handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData)
Definition: osiswebif.cpp:48
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77
static const SWBuf encode(const char *urlText)
Definition: url.cpp:231
virtual bool handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData)
Definition: osisxhtml.cpp:218
int getAttributePartCount(const char *attribName, char partSplit= '|') const
Definition: utilxml.cpp:218